modulepackage
0.0.5
Repository: https://github.com/hyperdriven/hyperdrive.git
Documentation: pkg.go.dev
# README
hyperdrive

An opinionated micro-framework for creating Hypermedia APIs in Go.
Install
go get github.com/hyperdriven/hyperdrive
OR
glide get github.com/hyperdriven/hyperdrive
Import
import "github.com/hyperdriven/hyperdrive"
Usage
Refer to our Quick Start Guide for how to use this package.
Config
Configuration of core features are done via Environment Variables, in accordence with 12 factor principles, and is detailed here
Contributing
Refer to our Contributor's Guide to learn more about how you can partipicate.
More Info
# Functions
BodyParams deserializes the input, and extracts the values from the request body.
GetContentTypeJSON returns the json Content-Type an endpoint can accept and respond with.
GetContentTypes returns a slice of Content-Types that the endpoint can accept and respond with.
GetContentTypesList returns a list of Content-Type strings that the endpoint can accept and respond with.
GetContentTypeXML returns the xml Content-Type an endpoint can accept and respond with.
GetEncoder returns the correct ContentEncoder, determined by the Accept header, to support automatic Content Negotiation.
GetErrorText helps ensure implementation details are not leaked in production environments.
GetMediaType returns a media type string, sans any content-type extension (e.g.
GetMethods returns a slice of the methods an Endpoint supports.
GetMethodsList returns a list of the methods an Endpoint supports.
GetParams returns all allowed request params.
NewAPI creates an instance of API, with an initialized Router, Config, Server, and RootResource.
NewConfig returns an instance of config, with values loaded from ENV vars.
NewEndpoint creates an instance of Endpoint.
NewEndpointResource creates an instance of EndpointResource from the given Endpointer.
NewEndpointResourceParam creates an instance of EndpointResourceParam from the given parsedParam.
NewMethodHandler sets the correct http.Handler for each method, depending on the interfaces the Endpointer supports.
NewRootResource creates an instance of RootResource from the given API.
Params extracts the param values from all sources: query, body, and path -- in that order.
PathParams extracts the values from the request path which match named params in the route.
QueryParams extracts the values from the request QueryString.
Respond is a helper function to make it easy for an Endpointer's method handler (e.g.
# Structs
API is a logical collection of one or more endpoints, connecting requests to the response handlers using a gorlla mux Router.
Config holds configuration values from the environment, with sane defaults (where possible).
Endpoint is a basic implementation of the Endpointer interface and can be used directly if desired.
EndpointResource contains information about and Endpoint, and is the hypermedia respresentation returned by the Discovery URL endpoint for API clients to learn about the Endpoint.
EndpointResourceParam contains information about endpoint parameters, and is part of the hypermedia representation returned by the Discovery URL endpoint for API clients to learn about input allowed (and/or required) by the Endpoint.
JSONEncoder is an implementation of ContentEncoder and wraps the Encoder found in encoding/json package.
NullEncoder is an implementation of ContentEncoder, and is the default encoder used when Content Negotiation has falied.
RootResource contains information about the API and its Endpoints, and is the hypermedia respresentation returned by the Discovery URL endpoint for API clients to learn about the API.
XMLEncoder is an implementation of ContentEncoder and wraps the Encoder found in encoding/xml package.
# Interfaces
ContentEncoder interface wraps the details of encoding response bodies to support automatic Content Negotiation.
DeleteHandler interface is satisfied if the endpoint has implemented a http.Handler method called Delete().
Endpointer interface provides flexibility in how endpoints are created allowing for expressiveness in how developers make use of the hyperdrive package.
GetHandler interface is satisfied if the endpoint has implemented a http.Handler method called Get().
OptionsHandler interface is satisfied if the endpoint has implemented a http.Handler method called Options().
Parameter is an interface to allow users to create self-describing custom types to be used as endpoint params.
PatchHandler interface is satisfied if the endpoint has implemented a http.Handler method called Patch().
PostHandler interface is satisfied if the endpoint has implemented a http.Handler method called Post().
PutHandler interface is satisfied if the endpoint has implemented a http.Handler method called Put().