func (u *ProfileApi) insert(r *restful.Request, w *restful.Response) {
	c := appengine.NewContext(r.Request)
	p := new(Profile)
	err := r.ReadEntity(&p)
	if err != nil {
		w.WriteError(http.StatusNotAcceptable, err)
		return
	}
	p.LastModified = time.Now()
	p.Email = user.Current(c).String()
	k, err := datastore.Put(c, datastore.NewIncompleteKey(c, "profiles", nil), p)
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}
	w.AddHeader("Location", u.Path+"/"+k.Encode())
	w.WriteHeader(http.StatusCreated)
	w.WriteEntity(p)
}
POST http://localhost:8080/profiles
{"first_name": "Ivan", "nick_name": "Socks", "last_name": "Hawkes"}
package main
import (
	"github.com/emicklei/go-restful"
	"github.com/emicklei/go-restful/swagger"
	"google.golang.com/appengine"
	"google.golang.com/appengine/datastore"
	"google.golang.com/appengine/user"
	"net/http"
	"time"
)
type Profile struct {
	LastModified time.Time `json:"-" xml:"-"`
	Email        string    `json:"-" xml:"-"`
	FirstName    string    `json:"first_name" xml:"first-name"`
	NickName     string    `json:"nick_name" xml:"nick-name"`
	LastName     string    `json:"last_name" xml:"last-name"`
}
type ProfileApi struct {
	Path string
}
func gaeUrl() string {
	if appengine.IsDevAppServer() {
		return "http://localhost:8080"
	} else {
		return "http://federatedservices.appspot.com"
	}
}
func init() {
	u := ProfileApi{Path: "/profiles"}
	u.register()
	config := swagger.Config{
		WebServices:    restful.RegisteredWebServices(),
		WebServicesUrl: gaeUrl(),
		ApiPath:        "/apidocs.json",
		SwaggerPath: "/apidocs/",
		SwaggerFilePath: "static/swagger"}
	swagger.InstallSwaggerService(config)
}
func (u ProfileApi) register() {
	ws := new(restful.WebService)
	ws.
		Path(u.Path).
		Consumes(restful.MIME_JSON, restful.MIME_XML).
		Produces(restful.MIME_JSON, restful.MIME_XML)
	ws.Route(ws.POST("").To(u.insert).
		Doc("insert a new profile").
		Param(ws.BodyParameter("Profile", "representation of a profile").DataType("main.Profile")).
		Reads(Profile{}))
	ws.Route(ws.GET("/{profile-id}").To(u.read).
		Doc("read a profile").
		Param(ws.PathParameter("profile-id", "identifier for a profile").DataType("string")).
		Writes(Profile{}))
	ws.Route(ws.PUT("/{profile-id}").To(u.update).
		Doc("update an existing profile").
		Param(ws.PathParameter("profile-id", "identifier for a profile").DataType("string")).
		Param(ws.BodyParameter("Profile", "representation of a profile").DataType("main.Profile")).
		Reads(Profile{}))
	ws.Route(ws.DELETE("/{profile-id}").To(u.remove).
		Doc("remove a profile").
		Param(ws.PathParameter("profile-id", "identifier for a profile").DataType("string")))
	restful.Add(ws)
}