Skip to content

threatmate/restfulwrapper

Repository files navigation

restfulwrapper

GitHub tag (latest SemVer) PkgGoDev

This is a wrapper around go-restful to make it easier to use.

Usage

This is a simple case of a single API container with a single endpoint.

type API struct{}

type GetMetadata struct {
	restfulwrapper.HTTPMethodGET
	_ string `api:"httppath:/"`
	_ string `api:"doc" description:"Handle a GET request."`
	_ string `api:"notes" description:""`
}
type GetOutput struct{}

func (a *API) Get(ctx context.Context, meta GetMetadata) (output GetOutput, err error) {
	output = GetOutput{}

	// ...

	return output, nil
}

// ...

webService := restfulwrapper.WebService("/api").
	Consumes(restful.MIME_JSON).
	Produces(restful.MIME_JSON)
{
	session := webService.Session()
	session.Register(ctx, "/v1/path/to/service", &API{})
}

container := restful.NewContainer()
container.Add(webService.WebService())

// Use container as you would any `http.Handler`.

An API struct can embed other API structs using httppath:

type API struct{
	_ OtherAPI `api:"httppath:/other-api"`
}

About

A better wrapper around go-restful.

Resources

Stars

Watchers

Forks

Releases

Packages

Used by

Contributors

Languages