rest

package
v6.0.2+incompatible Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2015 License: MIT Imports: 2 Imported by: 2

Documentation

Overview

Package rest provides a simple and opinionated rest rest

Principles

1. RESTs must not know about the route they are mounted to. Mount rest from the outside just like handlers. 2. Leave dispatching based on paths to extra muxers, like http.ServeMux 3. Route paths may only have one parameter or no parameter 4. If a route paths ends with a slash, there is no parameter. 5. If a route path does not end with a slash, the parameter is the trimmed part of the url path from the last slash to the end 6. Other parameters must be part of the url query params or be inside the request body. 7. There is just one muxer that dispatches based on the url path and it is used at the top level 8. There are no sub rests / no hierarchie of rests. Each rest is independent from the other. 9. The mounting of handlers on paths and subpaths must be defined inside an app. 10. There is an example how that could be done. 11. Each rest can only have a max of 7 handlers: One for the methods GET, PUT, PATCH, DELETE, HEAD and POST and an index handler 12. The index handler is called for GET requests with a path ending with a slash.

This leads to

1. Decoupled rests that can easily be mounted anywhere. 2. Fast and flexible mount paths without a need for placeholders, parsing or regular expressions. 3. Parameter type conversion inside the handlers where it belongs to. 4. Flexible integration of middleware around and within rests. 5. URLs are simply strings that could be stored in variables and parametrized by concatenation. 6. No special knowledge about url handling and rest internals required.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsIndex

func IsIndex(req *http.Request) bool

IsIndex checks if the given request is an index request

func Param

func Param(req *http.Request) string

Types

type REST

type REST [7]http.Handler

REST is an array of maximal 6 handlers One for the methods GET, PUT, PATCH, DELETE, HEAD and POST and the index handler Each handler may be missing; then a 404 status will be written for requests of that method

func Delete

func Delete(h http.Handler) REST

Delete creates a REST and registers the handler via Delete method call

func DeleteFunc

func DeleteFunc(fn func(wr http.ResponseWriter, req *http.Request)) REST

DeleteFunc is like Delete but for http.HandlerFunc

func Get

func Get(h http.Handler) REST

Get creates a REST and registers the handler via Get method call

func GetFunc

func GetFunc(fn func(wr http.ResponseWriter, req *http.Request)) REST

GetFunc is like Get but for http.HandlerFunc

func Head(h http.Handler) REST

Head creates a REST and registers the handler via Head method call

func HeadFunc

func HeadFunc(fn func(wr http.ResponseWriter, req *http.Request)) REST

HeadFunc is like Head but for http.HandlerFunc

func Index

func Index(h http.Handler) REST

Index creates a REST and registers the handler via Index method call

func IndexFunc

func IndexFunc(fn func(wr http.ResponseWriter, req *http.Request)) REST

IndexFunc is like Index but for http.HandlerFunc

func Patch

func Patch(h http.Handler) REST

Patch creates a REST and registers the handler via Patch method call

func PatchFunc

func PatchFunc(fn func(wr http.ResponseWriter, req *http.Request)) REST

PatchFunc is like Patch but for http.HandlerFunc

func Post

func Post(h http.Handler) REST

Post creates a REST and registers the handler via Post method call

func PostFunc

func PostFunc(fn func(wr http.ResponseWriter, req *http.Request)) REST

PostFunc is like Post but for http.HandlerFunc

func Put

func Put(h http.Handler) REST

Put creates a REST and registers the handler via Put method call

func PutFunc

func PutFunc(fn func(wr http.ResponseWriter, req *http.Request)) REST

PutFunc is like Put but for http.HandlerFunc

func (REST) Delete

func (r REST) Delete(h http.Handler) REST

Delete registers a handler for the DELETE method and an url path that has a parameter (does not end with a slash)

func (REST) DeleteFunc

func (r REST) DeleteFunc(fn func(wr http.ResponseWriter, req *http.Request)) REST

DeleteFunc is like Delete but for http.HandlerFunc

func (REST) Get

func (r REST) Get(h http.Handler) REST

Get registers a handler for the GET method and an url path that has a parameter (does not end with a slash)

func (REST) GetFunc

func (r REST) GetFunc(fn func(wr http.ResponseWriter, req *http.Request)) REST

GetFunc is like Get but for http.HandlerFunc

func (REST) Handler

func (r REST) Handler(method string, isIndex bool) (h http.Handler, found bool)

Handler returns the handler for the given method and index or non index. found is true if a handler could be found

func (REST) Head

func (r REST) Head(h http.Handler) REST

Head registers a handler for the HEAD method and an url path that has a parameter (does not end with a slash)

func (REST) HeadFunc

func (r REST) HeadFunc(fn func(wr http.ResponseWriter, req *http.Request)) REST

HeadFunc is like Head but for http.HandlerFunc

func (REST) Index

func (r REST) Index(h http.Handler) REST

Index registers a handler for the GET method and an url path that ends with a slash (no parameter)

func (REST) IndexFunc

func (r REST) IndexFunc(fn func(wr http.ResponseWriter, req *http.Request)) REST

IndexFunc is like Index but for http.HandlerFunc

func (REST) Options

func (r REST) Options(isIndex bool) (o []string)

Options returns the options (method) for index or non index requests

func (REST) Patch

func (r REST) Patch(h http.Handler) REST

Patch registers a handler for the PATCH method and an url path that has a parameter (does not end with a slash)

func (REST) PatchFunc

func (r REST) PatchFunc(fn func(wr http.ResponseWriter, req *http.Request)) REST

PatchFunc is like Patch but for http.HandlerFunc

func (REST) Post

func (r REST) Post(h http.Handler) REST

Post registers a handler for the POST method and an url path that ends with a slash (no parameter)

func (REST) PostFunc

func (r REST) PostFunc(fn func(wr http.ResponseWriter, req *http.Request)) REST

PostFunc is like Post but for http.HandlerFunc

func (REST) Put

func (r REST) Put(h http.Handler) REST

Put registers a handler for the PUT method and an url path that has a parameter (does not end with a slash)

func (REST) PutFunc

func (r REST) PutFunc(fn func(wr http.ResponseWriter, req *http.Request)) REST

PutFunc is like Put but for http.HandlerFunc

func (REST) ServeHTTP

func (r REST) ServeHTTP(wr http.ResponseWriter, req *http.Request)

func (REST) ServeOptions

func (r REST) ServeOptions(wr http.ResponseWriter, req *http.Request)

ServeOptions serves the OPTIONS request

Directories

Path Synopsis
app

Jump to

Keyboard shortcuts

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