Documentation
¶
Overview ¶
Package containing the actual API functionality
Each file represents the API functionality for a certain database dbmodels (GET, POST, PUT, DELETE)
Index ¶
- Constants
- func ApiHandler(rw http.ResponseWriter, req *http.Request)
- func GiveApiMessage(statusCode int, message string, rw http.ResponseWriter)
- func GiveApiResponse(statusCode int, message []byte, rw http.ResponseWriter)
- func GiveApiStatus(statusCode int, rw http.ResponseWriter) string
- func PerformClientCall(handlerName string, rw http.ResponseWriter, req *http.Request, ...)
- type Api
- func (api *Api) DeleteEndpoint(vars *ApiVar, resp *ApiResponse) error
- func (api *Api) DeleteUserSession(vars *ApiVar, resp *ApiResponse) error
- func (api *Api) GenericDELETE(vars *ApiVar, resp *ApiResponse) error
- func (api *Api) GenericGET(vars *ApiVar, resp *ApiResponse) error
- func (api *Api) GenericPOST(vars *ApiVar, resp *ApiResponse) error
- func (api *Api) GenericPUT(vars *ApiVar, resp *ApiResponse) error
- func (api *Api) GetEndpoint(vars *ApiVar, resp *ApiResponse) error
- func (api *Api) GetRequestsHistory(vars *ApiVar, resp *ApiResponse) error
- func (api *Api) GetUserSession(vars *ApiVar, resp *ApiResponse) error
- func (api *Api) PostEndpoint(vars *ApiVar, resp *ApiResponse) error
- func (api *Api) PostUser(vars *ApiVar, resp *ApiResponse) error
- func (api *Api) PostUserSession(vars *ApiVar, resp *ApiResponse) error
- func (api *Api) PutEndpoint(vars *ApiVar, resp *ApiResponse) error
- type ApiResponse
- type ApiVar
- type BasicAuthentication
Constants ¶
const ( GET = "GET" POST = "POST" PUT = "PUT" DELETE = "DELETE" )
Variables ¶
This section is empty.
Functions ¶
func ApiHandler ¶
func ApiHandler(rw http.ResponseWriter, req *http.Request)
All the requests to the server go through this handler.
This parses requests, filters them and takes appropriate actions based on the content and configuration of each http request.
The actions to be taken are stored in the Routes configuration of the application
func GiveApiMessage ¶
func GiveApiMessage(statusCode int, message string, rw http.ResponseWriter)
Responds to the client that made the HTTP request with a status code and a simple message
func GiveApiResponse ¶
func GiveApiResponse(statusCode int, message []byte, rw http.ResponseWriter)
Responds to the client that made the HTTP request with a status code and appropriate response data (usually JSON/XML encoded data)
func GiveApiStatus ¶
func GiveApiStatus(statusCode int, rw http.ResponseWriter) string
Responds to the client that made the HTTP request with a status code and a default message for that status code
func PerformClientCall ¶
func PerformClientCall(handlerName string, rw http.ResponseWriter, req *http.Request, route *config.Route)
Performs a call to the RPC server using the appropriate data extracted from the HTTP request, which is stored in the specific API variable
Types ¶
type Api ¶
type Api int
Used for defining a type representing the api
func (*Api) DeleteEndpoint ¶
func (api *Api) DeleteEndpoint(vars *ApiVar, resp *ApiResponse) error
func (*Api) DeleteUserSession ¶
func (api *Api) DeleteUserSession(vars *ApiVar, resp *ApiResponse) error
func (*Api) GenericDELETE ¶
func (api *Api) GenericDELETE(vars *ApiVar, resp *ApiResponse) error
func (*Api) GenericGET ¶
func (api *Api) GenericGET(vars *ApiVar, resp *ApiResponse) error
func (*Api) GenericPOST ¶
func (api *Api) GenericPOST(vars *ApiVar, resp *ApiResponse) error
func (*Api) GenericPUT ¶
func (api *Api) GenericPUT(vars *ApiVar, resp *ApiResponse) error
func (*Api) GetEndpoint ¶
func (api *Api) GetEndpoint(vars *ApiVar, resp *ApiResponse) error
func (*Api) GetRequestsHistory ¶
func (api *Api) GetRequestsHistory(vars *ApiVar, resp *ApiResponse) error
func (*Api) GetUserSession ¶
func (api *Api) GetUserSession(vars *ApiVar, resp *ApiResponse) error
func (*Api) PostEndpoint ¶
func (api *Api) PostEndpoint(vars *ApiVar, resp *ApiResponse) error
func (*Api) PostUserSession ¶
func (api *Api) PostUserSession(vars *ApiVar, resp *ApiResponse) error
func (*Api) PutEndpoint ¶
func (api *Api) PutEndpoint(vars *ApiVar, resp *ApiResponse) error
type ApiResponse ¶
Data type containing important data that will be sent as response to HTTP requests
type ApiVar ¶
type ApiVar struct { Route config.Route RequestMethod string RequestHeader http.Header RequestForm url.Values RequestContentLength int64 RequestBody []byte BasicAuth BasicAuthentication }
Data type containing important data from a HTTP request that has been made to the server
type BasicAuthentication ¶
Data type containing the basic auth details