api

package
v0.0.0-...-d1a64ea Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 22, 2016 License: MIT Imports: 7 Imported by: 0

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

View Source
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"
)
View Source
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"
)
View Source
const (
	// StatusTooManyRequests is used for issuing errors regarding the number of request made by a client
	StatusTooManyRequests = 429
)

Variables

View Source
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

func StatusText(statusCode int) string

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

func BadRequest(err error) Response

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

func DataResponse(statusCode int, data []byte, contetType string) Response

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

func FileResponse(statusCode int, contentType, fullFilePath string) Response

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

func InternalServerError(err error) Response

InternalServerError returns a status and message that signals the API client about an 'internal server error' that has occured

func JSONResponse

func JSONResponse(statusCode int, data interface{}) Response

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

func NotFound(err error) Response

NotFound returns a status and message that signals the API client that the searched resource was not found on the server

func PlainTextResponse

func PlainTextResponse(statusCode int, text string) Response

PlainTextResponse creates a Response from the api, containing a status code and a text message

func ServiceUnavailable

func ServiceUnavailable(err error) Response

ServiceUnavailable returns a status and message that signals the API client that the accessed endpoint is either disabled or currently unavailable

func StatusResponse

func StatusResponse(statusCode int) Response

StatusResponse creates a Response from the api, containing just a status code

func TextResponse

func TextResponse(statusCode int, text, contentType string) Response

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

Directories

Path Synopsis
app

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL