HttpApi
The HttpApi
is used to access various HTTP server functionalities including authentication, routing, and http responses.
1. HttpApi Methods
The following are the available methods in HttpApi
:
GetClientDevice
Get the client device info from the http request:
// handler
func (w http.ResponseWriter, r *http.Request) {
device := api.Http().Helpers().GetClientDevice(r)
fmt.Println(device) // ClientDevice
}
Auth
It returns an instance of the HttpAuth.
Middlewares
It returns an instance of HttpMiddlewares that contains the built-in middlewares.
Helpers
It returns an instance of the HttpHelpers.
HttpRouter
It returns an instance of HttpRouterApi.
HttpResponse
Returns an instance of HttpResponse.
VueRouter
It returns an instance of VueRouterApi.
VueResponse
Returns an instance of VueResponse.
MuxVars
Returns a map[string]string
of variables from the request path. Below is an example to get the value if id
in the route path /sessions/:id
// handler
func (w http.ResponseWriter, r *http.Request) {
// other logic...
vars := api.Http().MuxVars(r) // map[string]string
id := vars["id"]
fmt.Println(id) // "1"
}
GetAdminNavs
Returns a slice of AdminNavList
// handler
func (w http.ResponseWriter, r *http.Request) {
// other logic...
acct, _ := api.Http().Auth().CurrentAccount(r)
navList := api.Http().GetAdminNavs(acct)
fmt.Println(navList) // []AdminNavList
}
GetPortalItems
Returns a slice of PortalItem
// handler
func (w http.ResponseWriter, r *http.Request) {
// other logic...
clnt, _ := api.Http().GetClientDevice(r)
portalItems := api.Http().GetPortalItems(clnt)
fmt.Println(portalItems) // []PortalItem
}
2. Admin Nav List
AdminNavList
contains a list of items for the admin navigation. It has the following fields:
3. Admin Nav Item
AdminNavItem
is an item for the admin navigation. It has the following fields:
type AdminNavItem struct {
Category INavCategory `json:"category"`
Label string `json:"label"`
VueRouteName string `json:"route_name"`
VueRoutePath string `json:"route_path"`
VueRouteParams map[string]string `json:"route_params"`
}
4. Portal Item
PortalItem
is an item for the portal navigation. It has the following fields: