Skip to content

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.

auth := api.Http().Auth()

Middlewares

It returns an instance of HttpMiddlewares that contains the built-in middlewares.

middlewares := api.Http().Middlewares()

Helpers

It returns an instance of the HttpHelpers.

helpers := api.Http().Helpers()

HttpRouter

It returns an instance of HttpRouterApi.

httpRouter := api.Http().HttpRouter()

HttpResponse

Returns an instance of HttpResponse.

httpResponse := api.Http().HttpResponse()

VueRouter

It returns an instance of VueRouterApi.

vueRouter := api.Http().VueRouter()

VueResponse

Returns an instance of VueResponse.

vueResponse := api.Http().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:

type AdminNavList struct {
    Label string         `json:"label"`
    Items []AdminNavItem `json:"items"`
}

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:

type PortalItem struct {
    IconUri        string            `json:"icon_uri"`
    Label          string            `json:"label"`
    VueRouteName   string            `json:"route_name"`
    VueRoutePath   string            `json:"route_path"`
    VueRouteParams map[string]string `json:"route_params"`
}