Documentation ¶
Index ¶
- func AddCookie(c *http.Cookie) action.Converter[*http.Request, *http.Request]
- func AddHeader(k, v string) action.Converter[*http.Request, *http.Request]
- func ApplyBody(r io.ReadCloser) action.Converter[*http.Request, *http.Request]
- func FetchResp() action.Converter[*http.Request, *http.Response]
- func FetchRespWithClient() action.C2[*http.Client, *http.Request, *http.Response]
- func NewRequest() action.C2[string, string, *http.Request]
- func Request(method, uri string) action.Data[*http.Request]
- func SetContentType(typ string) action.Converter[*http.Request, *http.Request]
- func SetHeader(k, v string) action.Converter[*http.Request, *http.Request]
- func SetURLEncoded(_ context.Context, req *http.Request) (*http.Request, error)
- func UseBody[T io.ReadCloser](b action.Data[T]) action.Converter[*http.Request, *http.Request]
- func UseGetBody[T io.ReadCloser](b action.Data[T]) action.Converter[*http.Request, *http.Request]
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FetchResp ¶
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 ¶
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 ¶
NewRequest creates an action.Data to build http client request with empty body.
func SetContentType ¶
func SetURLEncoded ¶
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.