rest

package module
v0.0.0-...-42bd765 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2012 License: MIT Imports: 8 Imported by: 0

README

A RESTful HTTP client and server.

goci:

docs: http://go.pkgdoc.org/github.com/nathankerr/rest

Install by running:

go get github.com/nathankerr/rest

Checkout examples/snips/snips.go for a simple client and server example

rest 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, *http.Request)
GET /resource/id => Find(http.ResponseWriter, id string, *http.Request)
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, *http.Request)
OPTIONS /resource/ => Options(http.ResponseWriter, id string, *http.Request)
OPTIONS /resource/id => Options(http.ResponseWriter, id string, *http.Request)

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.

Documentation

Overview

A RESTful HTTP client and server.

rest 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

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 NoContent

func NoContent(c http.ResponseWriter)

Emits a 204 No Content

func NotFound

func NotFound(c http.ResponseWriter)

Emits a 404 Not Found

func NotImplemented

func NotImplemented(c http.ResponseWriter)

Emits a 501 Not Implemented

func Resource

func Resource(name string, res interface{})

Add a resource route to http

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

func NewClient(resource string) (*Client, error)

Creates a client for the specified resource.

The resource is the url to the base of the resource (i.e., http://127.0.0.1:3000/snips/)

func (*Client) Close

func (client *Client) Close()

Closes the clients connection

func (*Client) Create

func (client *Client) Create(body string) (*http.Response, error)

POST /resource

func (*Client) Delete

func (client *Client) Delete(id string) (*http.Response, error)

DELETE /resource/id

func (*Client) Find

func (client *Client) Find(id string) (*http.Response, error)

GET /resource/id

func (*Client) IdFromURL

func (client *Client) IdFromURL(urlString string) (string, error)

Parse a response-Location-URI to get the ID of the worked-on snip

func (*Client) Index

func (client *Client) Index() (*http.Response, error)

GET /resource/

func (*Client) Request

func (client *Client) Request(request *http.Request) (*http.Response, error)

Send a request

func (*Client) Update

func (client *Client) Update(id string, body string) (*http.Response, error)

PUT /resource/id

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.

Jump to

Keyboard shortcuts

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