go-restful first working example
In a previous post, I discussed the design of go-restful which is a package for building REST-style WebServices using the Google Go programming language.
Today, I completed the implementation of that package which provides the basics:
- Creating a WebService with Routes (mapping between Http Request and a Go function)
- Each Route requires information about the Http method (GET,POST,...), URL Path (/users..), Mime-types and the function it binds to
- Functions get passed in a Request and a Response
- The Request is used to access Path and Query parameters , Headers and request content (XML, JSON,...)
- The Response is used to set Status, Headers, and response content
- Both Request and Response can Unmarshal and Marshal objects to and from XML,JSON using the standard packages
package userservice
import (
"github.com/emicklei/go-restful"
"log"
)
type User struct {
Id, Name string
}
Type User represents our domain object.