Documentation ¶
Overview ¶
Package httpapi combine the popular httprouter package and alice to bring the best of both worlds when creating http apis.
Index ¶
- func WriteJSON(w http.ResponseWriter, v interface{}) error
- type Handle
- type HandleFunc
- type HandleFunc2
- type HandleFunc3
- type HandleFunc4
- type Param
- type Params
- type Router
- func (r *Router) Delete(path string, handle interface{})
- func (r *Router) Get(path string, handle interface{})
- func (r *Router) Group(path string) *Router
- func (r *Router) Handle(method, path string, handle interface{})
- func (r *Router) Handler(method, path string, handler http.Handler)
- func (r *Router) Head(path string, handle interface{})
- func (r *Router) Options(path string, handle interface{})
- func (r *Router) Patch(path string, handle interface{})
- func (r *Router) Post(path string, handle interface{})
- func (r *Router) Put(path string, handle interface{})
- func (r *Router) ServeFiles(path string, root http.FileSystem)
- func (r *Router) ServeHTTP(w http.ResponseWriter, req *http.Request)
- func (r *Router) Use(mwf ...interface{})
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func WriteJSON ¶
func WriteJSON(w http.ResponseWriter, v interface{}) error
WriteJSON writes interface as JSON to response writer. If a error occurred a internal server error status will be written.
Types ¶
type Handle ¶
type Handle = httprouter.Handle
Handle is httprouter's function that can be in middlewares. Handle is a function that can be registered to a route to handle HTTP requests. Just a alias for httprouter.Handle.
func DefaultResponseHandle ¶
func DefaultResponseHandle(fn HandleFunc) Handle
DefaultResponseHandle is the default response handle.
type HandleFunc ¶
type HandleFunc func(r *http.Request, ps httprouter.Params) (interface{}, interface{})
HandleFunc is a function that can be registered to be a route to handle HTTP requests.
type HandleFunc2 ¶
HandleFunc2 is a function that can be registered to be a route to handle HTTP requests. HandleFunc2 does only have http request as a argument.
type HandleFunc3 ¶
type HandleFunc3 func() (interface{}, interface{})
HandleFunc3 is a function that can be registered to be a route to handle HTTP requests. HandleFunc3 does only have params as a argument.
type HandleFunc4 ¶
type HandleFunc4 func() (interface{}, interface{})
HandleFunc4 is a function that can be registered to be a route to handle HTTP requests. HandleFunc4 does not have any arguments.
type Param ¶
type Param = httprouter.Param
Param is a single URL parameter, consisting of a key and a value. Just a alias for httprouter.Param.
type Params ¶
type Params = httprouter.Params
Params is a Param-slice, as returned by the router. Just a alias for httprouter.Params.
func ParamsFromContext ¶
ParamsFromContext pulls the URL parameters from a request context, or returns nil if none are present. Just a alias function for httprouter.ParamsFromContext.
type Router ¶
type Router struct { ResponseHandle func(HandleFunc) httprouter.Handle // contains filtered or unexported fields }
Router represents the router.
func (*Router) Group ¶
Group returns new *Router with given path and middlewares. It should be used for handles which have same path prefix or common middlewares.
func (*Router) Handler ¶
Handler is an adapter which allows the usage of an http.Handler as a request handle. Just a alias function for httprouter's Handler.
func (*Router) ServeFiles ¶
func (r *Router) ServeFiles(path string, root http.FileSystem)
ServeFiles serves files from the given file system root. Just a alias function for httprouter's ServeFiles. Read more: https://godoc.org/github.com/julienschmidt/httprouter#Router.ServeFiles