Documentation
¶
Overview ¶
Package api contains the API functionality helpers
Each package represents the API functionality of a certain endpoint which may implement some of the following functionalities: GET, POST, PUT or DELETE
Index ¶
- Constants
- Variables
- func StatusText(statusCode int) string
- type Request
- type Response
- func BadRequest(err error) Response
- func DataResponse(statusCode int, data []byte, contetType string) Response
- func FileResponse(statusCode int, contentType, fullFilePath string) Response
- func InternalServerError(err error) Response
- func JSONResponse(statusCode int, data interface{}) Response
- func MethodNotAllowed() Response
- func NotFound(err error) Response
- func PlainTextResponse(statusCode int, text string) Response
- func ServiceUnavailable(err error) Response
- func StatusResponse(statusCode int) Response
- func TextResponse(statusCode int, text, contentType string) Response
- func Unauthorized() Response
Constants ¶
const ( // GET constant represents a GET type http request GET = "GET" // POST constant represents a POST type http request POST = "POST" // PUT constant represents a PUT type http request PUT = "PUT" // DELETE constant represents a DELETE type http request DELETE = "DELETE" )
const ( // ContentTextPlain represents a HTTP transfer with simple text data ContentTextPlain = "text/plain" // ContentHTML represents a HTTP transfer with html data ContentHTML = "text/html" // ContentJSON represents a HTTP transfer with JSON data ContentJSON = "application/json" )
const (
// StatusTooManyRequests is used for issuing errors regarding the number of request made by a client
StatusTooManyRequests = 429
)
Variables ¶
var ( ErrEntityFormat = errors.New("The entity was not in the correct format") ErrEntityIntegrity = errors.New("The entity doesn't comply to the integrity requirements") ErrEntityProcessing = errors.New("The entity could not be processed") ErrEntityNotFound = errors.New("No entity with the specified data was found") ErrIDParamNotSpecified = errors.New("No id was specified for the entity to be updated") ErrInvalidIDParam = errors.New("The id parameter is not a valid bson.ObjectId") ErrInvalidInput = errors.New("The needed url paramters were inexistent or invalid") )
Common errors returned by the API
Functions ¶
func StatusText ¶
StatusText returns the message associated to a http status code
Types ¶
type Request ¶
type Request struct { Header http.Header Form url.Values ContentLength int64 Body []byte Identity *identity.Identity ClientDetails *cookies.Client }
A Request contains the important and processable data from a HTTP request
type Response ¶
type Response struct { Content []byte StatusCode int ErrorMessage string ContentType string File string }
A Response contains the information that will be sent back to the user through a HTTP response
func BadRequest ¶
BadRequest returns a status and message that signals the API client about a 'bad request' that the client has made to the server
func DataResponse ¶
DataResponse creates a Response from the api, containing a status code, a custom content-type and a message in the form of a byte array
func FileResponse ¶
FileResponse creates a Response from the api, containing a file path (download, load or stream) and the content type of the file that is returned
func InternalServerError ¶
InternalServerError returns a status and message that signals the API client about an 'internal server error' that has occured
func JSONResponse ¶
JSONResponse creates a Response from the api, containing a single entity encoded as JSON
func MethodNotAllowed ¶
func MethodNotAllowed() Response
MethodNotAllowed returns a status and message that signals the API client that the used HTTP Method is not allowed on this endpoint
func NotFound ¶
NotFound returns a status and message that signals the API client that the searched resource was not found on the server
func PlainTextResponse ¶
PlainTextResponse creates a Response from the api, containing a status code and a text message
func ServiceUnavailable ¶
ServiceUnavailable returns a status and message that signals the API client that the accessed endpoint is either disabled or currently unavailable
func StatusResponse ¶
StatusResponse creates a Response from the api, containing just a status code
func TextResponse ¶
TextResponse creates a Response from the api, containing a status code, a text message and a custom content-type
func Unauthorized ¶
func Unauthorized() Response
Unauthorized returns a status and message that signals the API client that the login failed or that the client isn't logged in and therefore not authorized to use the endpoint