This is a small library that enables you to quickly create named endpoint functionality with near effortless documentation for API users.
There is a single public function and a single public interface to use.
func NewHttpHandler(points []Namepoint, headers map[string]string) (http.Handler, error)
This creates a http.Handler for use in the standard library.
The passed in interface appears below.
type Namepoint interface {
Name() string
UpdatesData() bool
Request() *jsonschema.Schema
Response() *jsonschema.Schema
GetResponse(r *http.Request) (interface{}, error)
}
The generated http.Handler creates an API with the following conventions:
- All requests will be POSTs at the root
- The query param
name
will determine whichNamepoint
will handle the http.Request - Passing in an unknown name will return all possible
name
s along with their json request/response schemas.
You can see an example of this in the examples/bookapi folder
https://github.com/stuartaroth/namepoints/tree/master/examples/bookapi