Skip to content

A quick and easy way to setup a RESTful JSON API

License

Notifications You must be signed in to change notification settings

gnusosa/go-json-rest

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Go-Json-Rest

A quick and easy way to setup a RESTful JSON API

Build Status

Go-Json-Rest is a thin layer on top of net/http that helps building RESTful JSON APIs easily. It provides fast URL routing using Go-UrlRouter, and helpers to deal with JSON requests and responses. It is not a high-level REST framework that transparently maps HTTP requests to procedure calls, on the opposite, you constantly have access to the underlying net/http objects.

Install

This package is "go-gettable", just do:

go get github.com/ant0ine/go-json-rest

Example

package main
import (
        "github.com/ant0ine/go-json-rest"
        "net/http"
)
type User struct {
        Id   string
        Name string
}
func GetUser(w *rest.ResponseWriter, req *rest.Request) {
        user := User{
                Id:   req.PathParam("id"),
                Name: "Antoine",
        }
        w.WriteJson(&user)
}
func main() {
        handler := ResourceHandler{}
        handler.SetRoutes(
                rest.Route{"GET", "/users/:id", GetUser},
        )
        http.ListenAndServe(":8080", &handler)
}

More Examples

  • Countries Demo very simple GET, POST, DELETE operations
  • Users Demo the mapping to object methods
  • SPDY Demo SPDY using github.com/shykes/spdy-go

Documentation

Copyright (c) 2013 Antoine Imbert

MIT License

About

A quick and easy way to setup a RESTful JSON API

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published