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 ¶
- func IsIndex(req *http.Request) bool
- func Param(req *http.Request) string
- type REST
- func Delete(h http.Handler) REST
- func DeleteFunc(fn func(wr http.ResponseWriter, req *http.Request)) REST
- func Get(h http.Handler) REST
- func GetFunc(fn func(wr http.ResponseWriter, req *http.Request)) REST
- func Head(h http.Handler) REST
- func HeadFunc(fn func(wr http.ResponseWriter, req *http.Request)) REST
- func Index(h http.Handler) REST
- func IndexFunc(fn func(wr http.ResponseWriter, req *http.Request)) REST
- func Patch(h http.Handler) REST
- func PatchFunc(fn func(wr http.ResponseWriter, req *http.Request)) REST
- func Post(h http.Handler) REST
- func PostFunc(fn func(wr http.ResponseWriter, req *http.Request)) REST
- func Put(h http.Handler) REST
- func PutFunc(fn func(wr http.ResponseWriter, req *http.Request)) REST
- func (r REST) Delete(h http.Handler) REST
- func (r REST) DeleteFunc(fn func(wr http.ResponseWriter, req *http.Request)) REST
- func (r REST) Get(h http.Handler) REST
- func (r REST) GetFunc(fn func(wr http.ResponseWriter, req *http.Request)) REST
- func (r REST) Handler(method string, isIndex bool) (h http.Handler, found bool)
- func (r REST) Head(h http.Handler) REST
- func (r REST) HeadFunc(fn func(wr http.ResponseWriter, req *http.Request)) REST
- func (r REST) Index(h http.Handler) REST
- func (r REST) IndexFunc(fn func(wr http.ResponseWriter, req *http.Request)) REST
- func (r REST) Options(isIndex bool) (o []string)
- func (r REST) Patch(h http.Handler) REST
- func (r REST) PatchFunc(fn func(wr http.ResponseWriter, req *http.Request)) REST
- func (r REST) Post(h http.Handler) REST
- func (r REST) PostFunc(fn func(wr http.ResponseWriter, req *http.Request)) REST
- func (r REST) Put(h http.Handler) REST
- func (r REST) PutFunc(fn func(wr http.ResponseWriter, req *http.Request)) REST
- func (r REST) ServeHTTP(wr http.ResponseWriter, req *http.Request)
- func (r REST) ServeOptions(wr http.ResponseWriter, req *http.Request)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type REST ¶
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 DeleteFunc ¶
func DeleteFunc(fn func(wr http.ResponseWriter, req *http.Request)) REST
DeleteFunc is like Delete but for http.HandlerFunc
func GetFunc ¶
func GetFunc(fn func(wr http.ResponseWriter, req *http.Request)) REST
GetFunc is like Get but for http.HandlerFunc
func HeadFunc ¶
func HeadFunc(fn func(wr http.ResponseWriter, req *http.Request)) REST
HeadFunc is like Head but for http.HandlerFunc
func IndexFunc ¶
func IndexFunc(fn func(wr http.ResponseWriter, req *http.Request)) REST
IndexFunc is like Index but for http.HandlerFunc
func PatchFunc ¶
func PatchFunc(fn func(wr http.ResponseWriter, req *http.Request)) REST
PatchFunc is like Patch but for http.HandlerFunc
func PostFunc ¶
func PostFunc(fn func(wr http.ResponseWriter, req *http.Request)) REST
PostFunc is like Post but for http.HandlerFunc
func PutFunc ¶
func PutFunc(fn func(wr http.ResponseWriter, req *http.Request)) REST
PutFunc is like Put but for http.HandlerFunc
func (REST) Delete ¶
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 ¶
DeleteFunc is like Delete but for http.HandlerFunc
func (REST) Get ¶
Get registers a handler for the GET method and an url path that has a parameter (does not end with a slash)
func (REST) Handler ¶
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 ¶
Head registers a handler for the HEAD method and an url path that has a parameter (does not end with a slash)
func (REST) Index ¶
Index registers a handler for the GET method and an url path that ends with a slash (no parameter)
func (REST) Patch ¶
Patch registers a handler for the PATCH method and an url path that has a parameter (does not end with a slash)
func (REST) Post ¶
Post registers a handler for the POST method and an url path that ends with a slash (no parameter)
func (REST) Put ¶
Put registers a handler for the PUT method and an url path that has a parameter (does not end with a slash)
func (REST) ServeOptions ¶
func (r REST) ServeOptions(wr http.ResponseWriter, req *http.Request)
ServeOptions serves the OPTIONS request