Skip to content

Kissaki/rest2go

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

58 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Rest2go

A RESTful HTTP client and server.

Installation

Install by running:

go get github.com/Kissaki/rest2go

Usage

See the examples folder for coded examples.

rest.go uses the standard http package to provide resources through specified resource routes. Add a new route and corresponding resource using the Resource method:

rest.Resource("resourcepath", resourcevariable)

The resource URI-path is then /resourcepath/.

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/       => Update(http.ResponseWriter, id string, *http.Request)
PUT /resource/id     => Update(http.ResponseWriter, id string, *http.Request)
DELETE /resource/    => Delete(http.ResponseWriter, id string)
DELETE /resource/id  => Delete(http.ResponseWriter, id string)
OPTIONS /resource/   => Options(http.ResponseWriter, id string)
OPTIONS /resource/id => Options(http.ResponseWriter, id string)

If you are not so familiar with the REST architecture, check these 2 wikipedia links for an overview:

If you want to add a permission/accessibility-check to the resource, implement

HasAccess(*http.Request) (bool, os.Error)

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. The weekdays example project implements a simple REST server.

About

RESTful HTTP service engine for Go

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 100.0%