Import it to your code 🔠
import (
alfJSON "github.com/PiterWeb/Alf-Router/utils/json"
)
Create your custom Struct or a Map
type MyCustomResponse struct {
Message string
}
Start sending JSON across your API Endpoints
err := alf.App(&alf.AppConfig{
Port: "3000",
Routes: alf.CreateRouter([]alf.Route{
{
Path: "/api",
Handle: func(ctx *alf.Ctx) error {
_, err := alfJSON.JSON(ctx, MyCustomResponse{
Message: "Hello World",
})
return err
},
Method: "get",
},
}),
})
if err != nil {
panic(err)
}