Documentation ¶
Overview ¶
Package rest provides RESTful support for applications.
type MyResource struct { } func (*MyResource) Path() string { return "/my/path" } func (*MyResource) GET(c context.Context) (interface{}, error) { return &myModel{}, nil } func (*MyResource) POST(c context.Context) (interface{}, error) { return &myModel{}, nil } func (*MyResource) DELETE(c context.Context) (interface{}, error) { return &myModel{}, nil }
Index ¶
- func EntityFromContext(c context.Context, v interface{}) error
- func ParamsFromContext(c context.Context) map[string]string
- func RequestFromContext(c context.Context) *http.Request
- func ResponseWriterFromContext(c context.Context) http.ResponseWriter
- func ValidEntityFromContext(c context.Context, v interface{}) error
- type Bundle
- type Consumes
- type DELETE
- type ErrorMapper
- type GET
- type HEAD
- type HTTPError
- type JSONProvider
- func (p *JSONProvider) ContentTypes() []string
- func (p *JSONProvider) IsReadable(r *http.Request, v interface{}) bool
- func (p *JSONProvider) IsWriteable(r *http.Request, v interface{}, w http.ResponseWriter) bool
- func (p *JSONProvider) Read(r *http.Request, v interface{}) error
- func (p *JSONProvider) Write(r *http.Request, v interface{}, w http.ResponseWriter) error
- type Metrics
- type POST
- type PUT
- type Produces
- type Provider
- type RequestReader
- type ResourceHandler
- type ResponseWriter
- type XMLProvider
- func (p *XMLProvider) ContentTypes() []string
- func (p *XMLProvider) IsReadable(r *http.Request, v interface{}) bool
- func (p *XMLProvider) IsWriteable(r *http.Request, v interface{}, w http.ResponseWriter) bool
- func (p *XMLProvider) Read(r *http.Request, v interface{}) error
- func (p *XMLProvider) Write(r *http.Request, v interface{}, w http.ResponseWriter) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EntityFromContext ¶
EntityFromContext returns marshalled http.Request.Body.
func ParamsFromContext ¶
ParamsFromContext returns path params.
func RequestFromContext ¶
RequestFromContext returns http.Request. Panic if http.Request is not in the given context.
func ResponseWriterFromContext ¶
func ResponseWriterFromContext(c context.Context) http.ResponseWriter
ResponseWriterFromContext returns http.ResponseWriter. Panic if http.ResponseWriter is not in the given context.
func ValidEntityFromContext ¶
ValidEntityFromContext is similar to EntityFromContext but also validate the entity.
Types ¶
type Bundle ¶
type Bundle struct { }
Bundle adds support for RESTful application.
func (*Bundle) Initialize ¶
type Consumes ¶
type Consumes interface {
Consumes() []string
}
Consumes defines the MIME Types that a resource can accept.
type ErrorMapper ¶
type ErrorMapper interface {
MapError(error, http.ResponseWriter, *http.Request)
}
ErrorMapper maps error to http error.
type HTTPError ¶
func NewHTTPError ¶
type JSONProvider ¶
type JSONProvider struct { }
JSONProvider reads JSON request and responds JSON.
func (*JSONProvider) ContentTypes ¶
func (p *JSONProvider) ContentTypes() []string
func (*JSONProvider) IsReadable ¶
func (p *JSONProvider) IsReadable(r *http.Request, v interface{}) bool
func (*JSONProvider) IsWriteable ¶
func (p *JSONProvider) IsWriteable(r *http.Request, v interface{}, w http.ResponseWriter) bool
func (*JSONProvider) Write ¶
func (p *JSONProvider) Write(r *http.Request, v interface{}, w http.ResponseWriter) error
type Metrics ¶
type Metrics interface {
Metrics() string
}
Metrics adds metrics of timing for the endpoint.
type Produces ¶
type Produces interface {
Produces() []string
}
Produces defines the MIME Types that a resource can produce.
type Provider ¶
type Provider interface { // ContentTypes returns list of MIME types associated with this provider. ContentTypes() []string RequestReader ResponseWriter }
Provider define reader and writer for particular MIME types.
type RequestReader ¶
type RequestReader interface { IsReadable(*http.Request, interface{}) bool Read(*http.Request, interface{}) error }
RequestReader reads entity from message body.
type ResourceHandler ¶
type ResourceHandler struct {
// contains filtered or unexported fields
}
ResourceHandler implements core.ResourceHandler
func NewResourceHandler ¶
func NewResourceHandler(env *core.Environment) *ResourceHandler
func (*ResourceHandler) AddProvider ¶
func (h *ResourceHandler) AddProvider(provider Provider)
AddProvider adds the given provider to the resource handler.
func (*ResourceHandler) HandleResource ¶
func (h *ResourceHandler) HandleResource(v interface{})
Handle must only be called after all providers are added.
type ResponseWriter ¶
type ResponseWriter interface { IsWriteable(*http.Request, interface{}, http.ResponseWriter) bool Write(*http.Request, interface{}, http.ResponseWriter) error }
ResponseWriter writes entity to message body.
type XMLProvider ¶
type XMLProvider struct { }
XMLProvider reads XML request and responds XML.
func (*XMLProvider) ContentTypes ¶
func (p *XMLProvider) ContentTypes() []string
func (*XMLProvider) IsReadable ¶
func (p *XMLProvider) IsReadable(r *http.Request, v interface{}) bool
func (*XMLProvider) IsWriteable ¶
func (p *XMLProvider) IsWriteable(r *http.Request, v interface{}, w http.ResponseWriter) bool
func (*XMLProvider) Write ¶
func (p *XMLProvider) Write(r *http.Request, v interface{}, w http.ResponseWriter) error