@@ -12,28 +12,43 @@ go get github.com/mix-go/xhttp
1212
1313| Function | Description |
1414| -----------------------------------------------------------------------------------------------------| -----------------------------------|
15- | xhttp.Fetch(ctx context.Context, method string, u string, opts ...RequestOption) (* Response, error) | Execute an http request. |
15+ | xhttp.Fetch(ctx context.Context, method string, u string, opts ...RequestOption) (* Response, error) | Send a http request. |
1616| xhttp.NewRequest(method string, u string, opts ...RequestOption) (* Request, error) | Create a request object. |
17- | xhttp.Do(ctx context.Context, req * Request, opts ...RequestOption) (* Response, error) | Execute an http request. |
18- | xhttp.DoRequest(ctx context.Context, req * http.Request, opts ...RequestOption) (* Response, error) | Execute an standard http request. |
19- | xhttp.WithBody(body Body) RequestOption | Set configuration item. |
20- | xhttp.WithHeader(header http.Header) RequestOption | Set configuration item. |
21- | xhttp.WithContentType(contentType string) RequestOption | Set configuration item. |
22- | xhttp.WithTimeout(timeout time.Duration) RequestOption | Set configuration item. |
23- | xhttp.WithDebugFunc(f DebugFunc) RequestOption | Set configuration item. |
24- | xhttp.WithRetry(f RetryIfFunc, opts ...retry.Option) RequestOption | Set configuration item. |
25- | xhttp.WithMiddleware(middlewares ...Middleware) RequestOption | Set configuration item. |
17+ | xhttp.Do(ctx context.Context, req * Request, opts ...RequestOption) (* Response, error) | Send a http request. |
18+ | xhttp.DoRequest(ctx context.Context, req * http.Request, opts ...RequestOption) (* Response, error) | Send a standard http request. |
19+ | xhttp.WithBody(body Body) RequestOption | Configure an option. |
20+ | xhttp.WithHeader(header http.Header) RequestOption | Configure an option. |
21+ | xhttp.WithContentType(contentType string) RequestOption | Configure an option. |
22+ | xhttp.WithTimeout(timeout time.Duration) RequestOption | Configure an option. |
23+ | xhttp.WithDebugFunc(f DebugFunc) RequestOption | Configure an option. |
24+ | xhttp.WithRetry(f RetryIfFunc, opts ...retry.Option) RequestOption | Configure an option. |
25+ | xhttp.WithMiddleware(middlewares ...Middleware) RequestOption | Configure an option. |
2626| xhttp.BuildJSON(v interface{}) Body | Generate json string. |
2727| xhttp.BuildQuery(m map[ string] string) Body | Generate urlencoded query string. |
2828| xhttp.Shutdown(ctx context.Context) | Do shutdown. |
2929
3030## Send a request
3131
32+ Send a simple request.
33+
3234``` go
3335url := " https://github.com/"
3436resp , err := xhttp.Fetch (context.Background (), http.MethodGet , url)
3537```
3638
39+ Configure some options.
40+
41+ ``` go
42+ url := " https://github.com/"
43+ header := make (http.Header )
44+ header.Set (" Authorization" , " Bearer ***" )
45+ resp , err := xhttp.Fetch (context.Background (), http.MethodGet , url,
46+ xhttp.WithContentType (" application/json" ),
47+ xhttp.WithHeader (header))
48+ ```
49+
50+ Create a request object and send the request.
51+
3752``` go
3853url := " https://github.com/"
3954req , err := xhttp.NewRequest (http.MethodGet , url)
@@ -43,6 +58,8 @@ if err != nil {
4358resp , err := xhttp.Do (context.Background (), req)
4459```
4560
61+ Create a standard request object and send the request.
62+
4663``` go
4764url := " https://github.com/"
4865req , err := http.NewRequest (http.MethodGet , url, nil )
0 commit comments