httpapi

package
v0.0.0-...-8e7039a Latest Latest
Warning

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

Go to latest
Published: May 24, 2017 License: GPL-3.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrorDateRequired = "DateHeaderRequired"
	ErrorDateInvalid  = "DateHeaderInvalid"
)
View Source
const (
	ErrorRequestBodyInvalid = "RequestBodyInvalid"
	ErrorRequestInvalid     = "InvalidRequest"
	ErrorRequestFailed      = "RequestFailed"

	HeaderGoblDate = "x-gobl-date"
	HeaderGoblSig  = "x-gobl-signature"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Normalize

type Normalize struct {
}

Normalize Middleware: It implements the ServeHTTP interface for negroni middleware. The function is to evaluate the incoming request and validate/store the required headers

func NewNormalize

func NewNormalize() *Normalize

func (Normalize) ServeHTTP

func (n Normalize) ServeHTTP(rw http.ResponseWriter, r *http.Request, next http.HandlerFunc)

ServeHTTP is the interface implementation for negroni middleware

type Request

type Request struct {
	Headers         http.Header
	RouteParameters httprouter.Params
	Body            io.ReadSeeker
	Host            string
	Path            string
	Method          string
	Query           url.Values
	Client          *http.Client
}

Request provides a starndardized way of accessing incoming requests We standardize information both for receiving and sending.

Context: It implements context functions for the context.Context package so that the rest of gobl can access the standardized parameters via the http.Request context

func NewRequest

func NewRequest(host, path, method string) *Request

func RequestFromContext

func RequestFromContext(ctx context.Context) *Request

RequestFromContext returns the reqest that has been stored in a context

func (*Request) JsonBody

func (r *Request) JsonBody(decodeTo interface{}) error

func (*Request) Send

func (r *Request) Send(s keys.Signer) (*Response, error)

func (*Request) SetBody

func (r *Request) SetBody(body interface{}) error

func (*Request) String

func (r *Request) String() string

String returns the request string that is appropriate for signing

type Response

type Response struct {
	// Data is API payload
	Data map[string]interface{} `json:"data,omitempty"`

	// Error holds any errors that were encountered processing the request
	Error error `json:"-"`

	// HTTPCode allows individual handlers to indiciate the appropriate http status code to return
	HTTPCode int `json:"-"`
}

Response is the standardized response format sent from the API

func (*Response) Write

func (r *Response) Write(rw http.ResponseWriter)

Write the standardized response to the given response writer

type Route

type Route struct {
	// Method is the HTTP method to listen on
	Method string

	// Path indictes the URL path. Wildcards in the form of :segment are supported
	// For more information see:
	// https://github.com/julienschmidt/httprouter
	Path string

	// Handler to use for this route
	Handler RouteHandler
}

Route defines a single endpoint

type RouteHandler

type RouteHandler func(*Request, httprouter.Params) Response

RouteHandler is the definition functions must meet to handle incoming requests

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server handles accepting and replying to API requests

func New

func New(routes []Route) *Server

New returns a new httpapi.Server configured to respond to the routes provided

func (*Server) Start

func (s *Server) Start(c config.Server, shutdown func())

Start listening on given address. The shutdown function will be called before the server exits

Jump to

Keyboard shortcuts

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