Documentation ¶
Overview ¶
Package http contains the helper functions for writing Spin HTTP components in TinyGo, as well as for sending outbound HTTP requests.
Index ¶
- Constants
- func Get(url string) (*http.Response, error)
- func Handle(fn func(http.ResponseWriter, *http.Request))
- func NewClient() *http.Client
- func NewTransport() http.RoundTripper
- func Post(url string, contentType string, body io.Reader) (*http.Response, error)
- func Send(req *http.Request) (*http.Response, error)
- type Param
- type Params
- type Router
- type RouterHandle
- type Transport
Constants ¶
const ( // The application base path. HeaderBasePath = "spin-base-path" // The component route pattern matched, _excluding_ any wildcard indicator. HeaderComponentRoot = "spin-component-route" // The full URL of the request. This includes full host and scheme information. HeaderFullUrl = "spin-full-url" // The part of the request path that was matched by the route (including // the base and wildcard indicator if present). HeaderMatchedRoute = "spin-matched-route" // The request path relative to the component route (including any base). HeaderPathInfo = "spin-path-info" // The component route pattern matched, as written in the component // manifest (that is, _excluding_ the base, but including the wildcard // indicator if present). HeaderRawComponentRoot = "spin-raw-component-route" // The client address for the request. HeaderClientAddr = "spin-client-addr" )
Variables ¶
This section is empty.
Functions ¶
func Get ¶
Get creates a GET HTTP request to a given URL and returns the HTTP response. The destination of the request must be explicitly allowed in the Spin application configuration, otherwise the request will not be sent.
func Handle ¶
func Handle(fn func(http.ResponseWriter, *http.Request))
Handle sets the handler function for the http trigger. It must be set in an init() function.
func NewTransport ¶
func NewTransport() http.RoundTripper
NewTransport returns http.RoundTripper backed by Spin SDK
Types ¶
type Param ¶
type Param = httprouter.Param
Param is a single URL parameter, consisting of a key and a value.
type Params ¶
type Params = httprouter.Params
Params is a Param-slice, as returned by the router. The slice is ordered, the first URL parameter is also the first slice value. It is therefore safe to read values by the index.
type Router ¶
type Router = httprouter.Router
Router is a http.Handler which can be used to dispatch requests to different handler functions via configurable routes
type RouterHandle ¶
type RouterHandle = httprouter.Handle
RouterHandle is a function that can be registered to a route to handle HTTP requests. Like http.HandlerFunc, but has a third parameter for the values of wildcards (variables).