http

package
v2.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 20, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

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

View Source
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

func Get(url string) (*http.Response, error)

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 NewClient

func NewClient() *http.Client

NewClient returns a new HTTP client compatible with the Spin SDK

func NewTransport

func NewTransport() http.RoundTripper

NewTransport returns http.RoundTripper backed by Spin SDK

func Post

func Post(url string, contentType string, body io.Reader) (*http.Response, error)

Post creates a POST HTTP request 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 Send

func Send(req *http.Request) (*http.Response, error)

Send sends an HTTP request and return the HTTP response. The destination of the request must be explicitly allowed in the Spin application configuration, otherwise the request will not be sent.

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

func NewRouter

func NewRouter() *Router

New returns a new initialized Router. Path auto-correction, including trailing slashes, is enabled by default.

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).

type Transport

type Transport struct{}

Transport implements http.RoundTripper

func (*Transport) RoundTrip

func (r *Transport) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip makes roundtrip using Spin SDK

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL