{"id":17330437,"url":"https://github.com/lxzan/hasaki","last_synced_at":"2025-04-14T16:33:31.245Z","repository":{"id":57483772,"uuid":"140711447","full_name":"lxzan/hasaki","owner":"lxzan","description":"golang http client","archived":false,"fork":false,"pushed_at":"2024-03-22T08:50:23.000Z","size":873,"stargazers_count":60,"open_issues_count":0,"forks_count":5,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-28T06:01:43.590Z","etag":null,"topics":["golang","http","http-client","http-requests","request"],"latest_commit_sha":null,"homepage":"https://pkg.go.dev/github.com/lxzan/hasaki","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lxzan.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-07-12T12:39:01.000Z","updated_at":"2025-02-12T06:37:52.000Z","dependencies_parsed_at":"2023-01-25T09:45:37.432Z","dependency_job_id":"bbca13ea-b3f0-4ef0-8884-c76b72c4c1d2","html_url":"https://github.com/lxzan/hasaki","commit_stats":null,"previous_names":[],"tags_count":38,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lxzan%2Fhasaki","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lxzan%2Fhasaki/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lxzan%2Fhasaki/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lxzan%2Fhasaki/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lxzan","download_url":"https://codeload.github.com/lxzan/hasaki/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248916962,"owners_count":21182900,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["golang","http","http-client","http-requests","request"],"created_at":"2024-10-15T14:51:16.882Z","updated_at":"2025-04-14T16:33:30.509Z","avatar_url":"https://github.com/lxzan.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n    \u003ch1\u003eHasaki\u003c/h1\u003e\n    \u003ch5\u003eHTTP Request Library for Go\u003c/h5\u003e\n    \u003cimg src=\"assets/logo.png\" alt=\"logo\" width=\"300px\"\u003e\n\u003c/div\u003e\n\n___\n\n[![go-test](https://github.com/lxzan/hasaki/workflows/Go%20Test/badge.svg?branch=master)](https://github.com/lxzan/hasaki/actions?query=branch%3Amaster) [![codecov](https://codecov.io/gh/lxzan/hasaki/graph/badge.svg?token=0VY55RLS3G)](https://codecov.io/gh/lxzan/hasaki)\n\n### Features\n\n-   [x] Buffer Pool\n-   [x] Trace the Error Stack\n-   [x] Build-In JSON / XML / WWWForm / Protobuf / YAML Codec \n-   [x] Request Before and After Middleware\n-   [x] Export cURL Command in Debug Mode\n\n### Install\n\n```bash\ngo get -v github.com/lxzan/hasaki\n```\n\n### Usage\n\n#### Get\n\n```go\n// GET https://api.example.com/search\n// Send get request with path parameters. Turn on data compression.\n\nresp := hasaki.\n    Get(\"https://api.example.com/%s\", \"search\").\n    SetHeader(\"Accept-Encoding\", \"gzip, deflate\").\n    Send(nil)\n```\n\n```go\n// GET https://api.example.com/search?q=hasaki\u0026page=1\n// Send get request, with Query parameter, encoded with url.Values\n\nresp := hasaki.\n    Get(\"https://api.example.com/search\").\n    SetQuery(url.Values{\n      \"q\":    []string{\"hasaki\"},\n      \"page\": []string{\"1\"},\n    }).\n    Send(nil)\n```\n\n#### Post\n\n```go\n// POST https://api.example.com/search\n// Send post request, encoded with json\n\ntype Req struct {\n    Q    string `json:\"q\"`\n    Page int    `json:\"page\"`\n}\nresp := hasaki.\n    Post(\"https://api.example.com/search\").\n    Send(Req{\n        Q:    \"hasaki\",\n        Page: 1,\n    })\n```\n\n```go\n// POST https://api.example.com/search\n// Send post request, encoded with www-form\n\nresp := hasaki.\n    Post(\"https://api.example.com/search\").\n    SetEncoder(hasaki.FormEncoder).\n    Send(url.Values{\n        \"q\":    []string{\"hasaki\"},\n        \"page\": []string{\"1\"},\n    })\n```\n\n#### Stream\n\n```go\n// POST https://api.example.com/upload\n// Send a put request, using a byte stream\n\nvar reader io.Reader\nencoder := hasaki.NewStreamEncoder(hasaki.MimeStream)\nresp := hasaki.\n    Put(\"https://api.example.com/upload\").\n    SetEncoder(encoder).\n    Send(reader)\n```\n\n#### Error Stack\n\n```go\n// Print the error stack\ndata := make(map[string]any)\nerr := hasaki.\n    Post(\"https://api.example.com/upload\").\n    Send(nil).\n    BindJSON(\u0026data)\nif err != nil {\n    log.Printf(\"%+v\", err)\n}\n```\n\n#### Middleware\n\nVery useful middleware, you can use it to do something before and after the request is sent.\n\nThe middleware is a function, it receives a context and a request or response object, and returns a context and an error.\n\nUnder code is a simple middleware example , record the request latency.\n\n```go\n// You can use the before and after middleware to do something before and after the request is sent\n\nbefore := hasaki.WithBefore(func(ctx context.Context, request *http.Request) (context.Context, error) {\n    return context.WithValue(ctx, \"t0\", time.Now()), nil\n})\n\nafter := hasaki.WithAfter(func(ctx context.Context, response *http.Response) (context.Context, error) {\n    t0 := ctx.Value(\"t0\").(time.Time)\n    log.Printf(\"latency=%s\", time.Since(t0).String())\n    return ctx, nil\n})\n\nvar url = \"https://api.github.com/search/repositories\"\ncli, _ := hasaki.NewClient(before, after)\ncli.Get(url).Send(nil)\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flxzan%2Fhasaki","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flxzan%2Fhasaki","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flxzan%2Fhasaki/lists"}