Documentation ¶
Overview ¶
A RESTful HTTP client and server.
rest.go uses the standard http package by adding resource routes. Add a new route by:
rest.Resource("resourcepath", resourcevariable)
and then use http as normal.
A resource is an object that may have any of the following methods which respond to the specified HTTP requests:
GET /resource/ => Index(http.ResponseWriter) GET /resource/id => Find(http.ResponseWriter, id string) POST /resource/ => Create(http.ResponseWriter, *http.Request) PUT /resource/id => Update(http.ResponseWriter, id string, *http.Request) DELETE /resource/id => Delete(http.ResponseWriter, id string) OPTIONS /resource/ => Options(http.ResponseWriter, id string) OPTIONS /resource/id => Options(http.ResponseWriter, id string)
The server will then route HTTP requests to the appropriate method call.
The snips example provides a full example of both a client and server.
Index ¶
- func BadRequest(c http.ResponseWriter, instructions string)
- func Created(c http.ResponseWriter, location string)
- func NoContent(c http.ResponseWriter)
- func NotFound(c http.ResponseWriter)
- func NotImplemented(c http.ResponseWriter)
- func Resource(name string, res interface{})
- func ResourceContentType(name string, contentType string)
- func SetResponseContentType(c http.ResponseWriter, resourceName string)
- func Updated(c http.ResponseWriter, location string)
- type Client
- func (client *Client) Close()
- func (client *Client) Create(body string) (*http.Response, error)
- func (client *Client) Delete(id string) (*http.Response, error)
- func (client *Client) Find(id string) (*http.Response, error)
- func (client *Client) IdFromURL(urlString string) (string, error)
- func (client *Client) Index() (*http.Response, error)
- func (client *Client) Request(request *http.Request) (*http.Response, error)
- func (client *Client) Update(id string, body string) (*http.Response, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BadRequest ¶
func BadRequest(c http.ResponseWriter, instructions string)
Emits a bad request with the specified instructions
func Created ¶
func Created(c http.ResponseWriter, location string)
Emits a 201 Created with the URI for the new location
func ResourceContentType ¶
Registers content type for given resource, e.g. ResourceContentType("foo", "application/json")
func SetResponseContentType ¶
func SetResponseContentType(c http.ResponseWriter, resourceName string)
func Updated ¶
func Updated(c http.ResponseWriter, location string)
Emits a 200 OK with a location. Used when after a PUT
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func NewClient ¶
Creates a client for the specified resource...doesn't work with weekly
The resource is the url to the base of the resource (i.e., http://127.0.0.1:3000/snips/)
Directories ¶
Path | Synopsis |
---|---|
examples
|
|
snips
Defines SnipsCollection struct-type and NewSnipsCollection() It is used by the example REST server for storing and managing snips It has the methods Add, WithId, All and Remove.
|
Defines SnipsCollection struct-type and NewSnipsCollection() It is used by the example REST server for storing and managing snips It has the methods Add, WithId, All and Remove. |