// NewAPIWithResolver can be used to create an API with a custom URL resolver. func NewAPIWithResolver(prefix string, resolver URLResolver) *API { handler := notAllowedHandler{} r := routing.NewHTTPRouter(prefix, &handler) api := newAPI(prefix, resolver, r) handler.API = api return api }
// NewAPI returns an initialized API instance // `prefix` is added in front of all endpoints. func NewAPI(prefix string) *API { handler := notAllowedHandler{} staticResolver := NewStaticResolver("") r := routing.NewHTTPRouter(prefix, &handler) api := newAPI(prefix, staticResolver, r) handler.API = api return api }
// NewAPIWithMarshalling does the same as NewAPIWithBaseURL with the addition // of a set of marshalers that provide a way to interact with clients that // use a serialization format other than JSON. The marshalers map is indexed // by the MIME content type to use for a given request-response pair. If the // client provides an Accept header the server will respond using the client's // preferred content type, otherwise it will respond using whatever content // type the client provided in its Content-Type request header. func NewAPIWithMarshalling(prefix string, resolver URLResolver, marshalers map[string]ContentMarshaler) *API { r := routing.NewHTTPRouter(prefix, notAllowedHandler{marshalers: marshalers}) return newAPI(prefix, resolver, marshalers, r) }