GitHub - emicklei/go-restful: package for building REST-style Web Services using Go (original) (raw)

go-restful

package for building REST-style Web Services using Google Go

Go Report Card Go Reference codecov

REST asks developers to use HTTP methods explicitly and in a way that's consistent with the protocol definition. This basic REST design principle establishes a one-to-one mapping between create, read, update, and delete (CRUD) operations and HTTP methods. According to this mapping:

Usage

Without Go Modules

All versions up to v2.*.* (on the master) are not supporting Go modules.

import (
    restful "github.com/emicklei/go-restful"
)

Using Go Modules

As of version v3.0.0 (on the v3 branch), this package supports Go modules.

import (
    restful "github.com/emicklei/go-restful/v3"
)

Example

ws := new(restful.WebService) ws. Path("/users"). Consumes(restful.MIME_XML, restful.MIME_JSON). Produces(restful.MIME_JSON, restful.MIME_XML)

ws.Route(ws.GET("/{user-id}").To(u.findUser). Doc("get a user"). Param(ws.PathParameter("user-id", "identifier of the user").DataType("string")). Writes(User{})) ...

func (u UserResource) findUser(request *restful.Request, response *restful.Response) { id := request.PathParameter("user-id") ... }

Full API of a UserResource

Features

How to customize

There are several hooks to customize the behavior of the go-restful package.

Resources

Type git shortlog -s for a full list of contributors.

© 2012 - 2023, http://ernestmicklei.com. MIT License. Contributions are welcome.