rest

package
v1.101.0 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package rest provides shared request helpers for the cloud API wrapper packages: context checking, JSON fetching, response nil-checking, and nextPageToken pagination.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Do

func Do(ctx context.Context, method string, urlString string, options []fetch_config.Option) error

Do performs a request with the given method, ignoring the response body.

func DoWithBody

func DoWithBody[B any](
	ctx context.Context,
	method string,
	urlString string,
	body B,
	options []fetch_config.Option,
) error

DoWithBody performs a request with the given method and JSON body, ignoring the response body.

func GetBytes added in v1.98.0

func GetBytes(ctx context.Context, urlString string, options []fetch_config.Option) ([]byte, string, error)

GetBytes performs a GET request and returns the response body as it is, with the content type it was served as: a file's content rather than a resource's description.

func GetJson

func GetJson[T any](ctx context.Context, urlString string, options []fetch_config.Option) (*T, error)

GetJson performs a GET request and returns the decoded, nil-checked response.

func ListPaginated

func ListPaginated[R any, T any](
	ctx context.Context,
	makeUrlString func(pageToken string) string,
	extract func(response *R) (items []T, nextPageToken string),
	options []fetch_config.Option,
) ([]T, error)

ListPaginated repeatedly performs GET requests, following the page token returned by extract until it is empty, and concatenates the extracted items.

func SendBytes added in v1.73.0

func SendBytes[T any](
	ctx context.Context,
	method string,
	urlString string,
	body []byte,
	contentType string,
	options []fetch_config.Option,
) (*T, error)

SendBytes performs a request with the given method and a raw body of the given content type, and returns the decoded, nil-checked JSON response.

func SendJson

func SendJson[T any, B any](
	ctx context.Context,
	method string,
	urlString string,
	body B,
	options []fetch_config.Option,
) (*T, error)

SendJson performs a request with the given method and JSON body and returns the decoded, nil-checked response.

func Url added in v1.99.0

func Url(base *url.URL, query url.Values, segments ...string) string

Url is base with the segments appended to its path, each escaped once as a single segment, and with the query. URL.String escapes Path, so PathEscape output put there would be escaped twice; RawPath carries the escaped form.

Types

This section is empty.

Jump to

Keyboard shortcuts

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