httpclient

所属分类:浏览器
开发工具:GO
文件大小:0KB
下载次数:0
上传日期:2023-09-13 02:09:49
上 传 者sh-1993
说明:  HTTP 2 Go编程语言客户端#golang#HTTP,
(HTTP 2 Client for Go Programming Language #golang #http,)

文件列表:
AUTHORS (124, 2023-12-05)
CODE_OF_CONDUCT.md (3230, 2023-12-05)
HISTORY.md (12, 2023-12-05)
LICENSE (1116, 2023-12-05)
SECURITY.md (750, 2023-12-05)
_examples/ (0, 2023-12-05)
_examples/weather/ (0, 2023-12-05)
_examples/weather/client.go (958, 2023-12-05)
_examples/weather/go.mod (345, 2023-12-05)
_examples/weather/go.sum (692, 2023-12-05)
_examples/weather/main.go (335, 2023-12-05)
_examples/weather/response.go (1490, 2023-12-05)
client.go (16273, 2023-12-05)
client_test.go (1485, 2023-12-05)
error.go (1750, 2023-12-05)
go.mod (80, 2023-12-05)
go.sum (153, 2023-12-05)
handler_transport.go (1177, 2023-12-05)
option.go (3183, 2023-12-05)
request_handler.go (1113, 2023-12-05)

# HTTP Client [![build status](https://img.shields.io/github/actions/workflow/status/kataras/httpclient/ci.yml?style=for-the-badge)](https://github.com/kataras/httpclient/actions) [![report card](https://img.shields.io/badge/report%20card-a%2B-ff3333.svg?style=for-the-badge)](https://goreportcard.com/report/github.com/kataras/httpclient) [![godocs](https://img.shields.io/badge/go-%20docs-488AC7.svg?style=for-the-badge)](https://pkg.go.dev/github.com/kataras/httpclient/) HTTP Client is a simple HTTP/2 client for Go. ```go package main import ( "context" "net/http" "net/url" "github.com/kataras/httpclient" ) // The BaseURL of our API client. const BaseURL = "https://api.weatherapi.com/v1" type ( Options struct { APIKey string `json:"api_key" yaml:"APIKey" toml:"APIKey"` } Client struct { *httpclient.Client } ) func NewClient(opts Options) *Client { apiKeyParameterSetter := httpclient.RequestParam("key", opts.APIKey) c := httpclient.New( httpclient.BaseURL(BaseURL), httpclient.PersistentRequestOptions(apiKeyParameterSetter), ) return &Client{c} } func (c *Client) GetCurrentByCity(ctx context.Context, city string) (resp Response, err error) { urlpath := "/current.json" // ?q=Athens&aqi=no params := httpclient.RequestQuery(url.Values{ "q": []string{city}, "aqi": []string{"no"}, }) err = c.Client.ReadJSON(ctx, &resp, http.MethodGet, urlpath, nil, params) return } ``` Some of the features HTTP Client offers: * Rate Limit * Middleware * JSON (read & write) * Forms * File Upload * Plain Text * Debug and more... ## Learning HTTP Client ### Installation The only requirement is the [Go Programming Language](https://go.dev/dl/). #### Create a new project ```sh $ mkdir myapp $ cd myapp $ go mod init myapp $ go get github.com/kataras/httpclient ```
Install on existing project ```sh $ cd myapp $ go get github.com/kataras/httpclient ``` **Run** ```sh $ go mod tidy $ go run . ```

Navigate through [_examples](_examples) folder for more. ## License This project is licensed under the [MIT License](LICENSE).

近期下载者

相关文件


收藏者