request

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package request builds and executes HTTP requests against a resolved environment.

Index

Constants

View Source
const MaxRedirects = 10

MaxRedirects matches the Go client's own default.

View Source
const StdinMarker = "@-"

StdinMarker is the --data value that means "read the body from stdin".

Variables

View Source
var ErrRedirectRefused = errors.New("redirect refused")

ErrRedirectRefused marks a redirect blip declined to follow, so it surfaces as a safety refusal rather than as a network failure.

Functions

func Data

func Data(value string, stdin io.Reader) ([]byte, error)

Data resolves a --data value: @file reads a file, @- reads stdin, anything else is the body itself.

func Fields

func Fields(pairs []string) ([]byte, error)

Fields builds a flat JSON object from repeated key=value pairs. A key ending in a colon (key:=value) takes its value as raw JSON, which is the only way to send a number, a boolean or null without guessing at what a string was meant to be.

func NewClient

func NewClient(env *config.Environment, timeout time.Duration) (*http.Client, error)

NewClient builds the HTTP client for talking to the API itself.

func NewStrictClient

func NewStrictClient(env *config.Environment, timeout time.Duration) (*http.Client, error)

NewStrictClient builds a client for a host that is not the API's own, such as an OAuth2 token endpoint. It always verifies TLS: `insecure` is granted for a localhost development certificate, and must not follow a credential to an identity provider somewhere else.

func ParseHeaders

func ParseHeaders(values []string) (http.Header, error)

ParseHeaders reads repeated --header values. Both "Name: value" and "Name=value" are accepted, because both are what people already have in their fingers.

func ParseQuery

func ParseQuery(values []string) (url.Values, error)

ParseQuery reads repeated --query values of the form name=value.

func ResolveURL

func ResolveURL(base *url.URL, rawPath string, query url.Values) (*url.URL, error)

ResolveURL applies a path and query to a base URL. A path prefix on the base URL is kept, so a base of https://host/api and a path of /orders give https://host/api/orders.

Types

type Request

type Request struct {
	Method string
	Path   string
	Query  url.Values
	Header http.Header
	Body   []byte
}

Request is a resolved call, before any base URL or credential is applied.

func (*Request) HTTPRequest

func (r *Request) HTTPRequest(ctx context.Context, base *url.URL) (*http.Request, error)

HTTPRequest turns a Request into something that can be sent.

type Response

type Response struct {
	Status int
	Header http.Header
	Body   []byte
}

Response is what came back, with the body already read.

func Do

func Do(client *http.Client, req *http.Request) (*Response, error)

Do sends a request. Every failure to get a response at all is a transport error, which is a different kind of problem from a response blip does not like.

Jump to

Keyboard shortcuts

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