httpact

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: May 15, 2024 License: MPL-2.0 Imports: 4 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddCookie

func AddCookie(c *http.Cookie) action.Converter[*http.Request, *http.Request]

func AddHeader

func AddHeader(k, v string) action.Converter[*http.Request, *http.Request]

func FetchResp

func FetchResp() action.Converter[*http.Request, *http.Response]

FetchResp converts http request into http response by sending request using http.DefaultClient.

Example
// fetch google.com
// - have a timeout of 1 minute
// - retry if failed, at most 3 times
// - final result is cached, preventing further requesting
getResp := FetchResp().Use(
	NewRequest().
		Apply(http.MethodGet).
		Apply("https://google.com").
		Then(ApplyBody(io.NopCloser(&bytes.Buffer{}))).
		With(task.Timeout(time.Minute)).
		Then(SetHeader("MyHeader", "MyVal")),
).RetryN(3).Cached()

resp, err := getResp(context.TODO())
_, _ = resp, err
Output:

func FetchRespWithClient

func FetchRespWithClient() action.C2[*http.Client, *http.Request, *http.Response]

FetchRespWitClient creates an action.C2 to send http request using an http client to retrieve http response.

The context is ignored. If you want to set timeout, set it on request (using action.Data.With) or http.Client.

func NewRequest

func NewRequest() action.C2[string, string, *http.Request]

NewRequest creates an action.Data to build http client request with empty body.

func Request

func Request(method, uri string) action.Data[*http.Request]

func SetContentType

func SetContentType(typ string) action.Converter[*http.Request, *http.Request]

func SetHeader

func SetHeader(k, v string) action.Converter[*http.Request, *http.Request]

func SetURLEncoded

func SetURLEncoded(_ context.Context, req *http.Request) (*http.Request, error)

Types

This section is empty.

Jump to

Keyboard shortcuts

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