http

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2023 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package http is a client package for WASM functions running within a Tarmac server.

This package provides user-friendly HTTP client functions that can interact with external HTTP services. Guest WASM functions running inside Tarmac can import and call this HTTP client.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client provides an interface to make outbound HTTP calls.

func New

func New(cfg Config) (*Client, error)

New creates a new Client with the provided configuration.

func (*Client) Delete

func (h *Client) Delete(url string) (Response, error)

Delete will perform a DELETE request using the URL specified.

func (*Client) Do

func (h *Client) Do(method string, headers map[string]string, url string, insecure bool, payload []byte) (Response, error)

Do will perform HTTP requests using the specified parameters. Valid Methods are GET, POST, PUT, and DELETE.

func (*Client) Get

func (h *Client) Get(url string) (Response, error)

Get will perform a GET request using the URL specified.

func (*Client) Post

func (h *Client) Post(url string, payload []byte) (Response, error)

Post will perform a POST request using the URL and Payload specified.

func (*Client) Put

func (h *Client) Put(url string, payload []byte) (Response, error)

Put will perform a PUT request using the URL and Payload specified.

type Config

type Config struct {
	// Namespace controls the function namespace to use for host callbacks. The default value is "default" which is the global namespace.
	// Users can provide an alternative namespace by specifying this field.
	Namespace string

	// HostCall is used internally for host callbacks. This is mainly here for testing.
	HostCall func(string, string, string, []byte) ([]byte, error)
}

Config provides users with the ability to specify namespaces, function handlers and other key information required to execute the function.

type Response

type Response struct {
	// StatusCode is the HTTP status code returned by the Client.
	StatusCode int

	// Headers are the returned HTTP headers from the server response.
	Headers map[string]string

	// Body is the returned HTTP body from the server response.
	Body []byte
}

Response is returned from successful client calls.

Jump to

Keyboard shortcuts

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