{"id":27637717,"url":"https://github.com/riyaz-ali/httpx","last_synced_at":"2025-04-23T21:18:39.138Z","repository":{"id":57530570,"uuid":"273842803","full_name":"riyaz-ali/httpx","owner":"riyaz-ali","description":"Simple and expressive HTTP testing framework","archived":false,"fork":false,"pushed_at":"2020-06-24T17:47:17.000Z","size":61,"stargazers_count":6,"open_issues_count":0,"forks_count":1,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-23T21:18:34.027Z","etag":null,"topics":["golang","http","testing"],"latest_commit_sha":null,"homepage":"https://go.riyazali.net/httpx","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/riyaz-ali.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}},"created_at":"2020-06-21T05:47:07.000Z","updated_at":"2023-06-14T00:14:41.000Z","dependencies_parsed_at":"2022-09-14T00:11:20.844Z","dependency_job_id":null,"html_url":"https://github.com/riyaz-ali/httpx","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/riyaz-ali%2Fhttpx","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/riyaz-ali%2Fhttpx/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/riyaz-ali%2Fhttpx/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/riyaz-ali%2Fhttpx/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/riyaz-ali","download_url":"https://codeload.github.com/riyaz-ali/httpx/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250514717,"owners_count":21443219,"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","testing"],"created_at":"2025-04-23T21:18:38.609Z","updated_at":"2025-04-23T21:18:39.116Z","avatar_url":"https://github.com/riyaz-ali.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# httpx\n\n[![Go v1.13](https://img.shields.io/badge/v1.13-blue.svg?labelColor=a8bfc0\u0026color=5692c7\u0026logoColor=fff\u0026style=for-the-badge\u0026logo=Go)](https://golang.org/doc/go1.13)\n[![Codecov coverage](https://img.shields.io/codecov/c/github/riyaz-ali/httpx/master.svg?color=5692c7\u0026logo=codecov\u0026logoColor=ffffff\u0026labelColor=a8bfc0\u0026style=for-the-badge\u0026label=)](https://codecov.io/gh/riyaz-ali/httpx)\n[![Github Actions](https://img.shields.io/github/workflow/status/riyaz-ali/httpx/Go%20-%20execute%20library%20tests/master.svg?color=5692c7\u0026logo=github-actions\u0026logoColor=ffffff\u0026labelColor=a8bfc0\u0026style=for-the-badge\u0026label=)](https://github.com/riyaz-ali/httpx/actions)\n[![Godoc](https://img.shields.io/badge/godoc-reference-blue.svg?labelColor=a8bfc0\u0026color=5692c7\u0026logoColor=fff\u0026style=for-the-badge)](https://pkg.go.dev/go.riyazali.net/httpx)\n![No added preservatives](https://img.shields.io/badge/No-Added_Preservatives-blue.svg?labelColor=a8bfc0\u0026color=5692c7\u0026logoColor=fff\u0026style=for-the-badge)\n\nSimple :bowtie:, elegant :snowflake: and concise :dart: tests for those HTTP endpoints in Go!\n\n## Overview\n\n**`httpx`** provides a minimal, yet powerful, function-driven framework to write simple and concise tests for HTTP, that reads like poem :notes:\n\nThe primary motivation is to enable developers to write self-describing and concise test cases, that also serves as documentation.\n\nUsing **`httpx`**, you can write your test cases like,\n\n```go\nimport (\n  . \"go.riyazali.net/httpx\"\n  \"testing\"\n)\n\nfunc TestHttpbinGet(t *testing.T) {\n  WithDefaultClient().\n    MakeRequest(\n      Get(Url(\"https://httpbin.org/get\", WithQueryParam(\"a\", \"1\"))),\n      WithHeader(\"Accept\", \"application/json\"),\n    ).\n    ExpectIt(t,\n      ToHaveStatus(http.StatusOK),\n    )\n}\n```\n\n**`httpx`** is quite versatile and allows you to use the same set of methods whether you are testing a remote endpoint (using `WithClient(...)`) or a local handler (using `WithHandler(...)`) :tada:\n\n## Usage\n\nTo use it, first install it using \n\n```shell\ngo get -u go.riyazali.net/httpx\n```\n\n**`httpx`** defines a set of core types all of which plugs into one another to provide a simple and cohesive framework.\n\nThe primary entry point into the framework is the [`ExecFn`](https://pkg.go.dev/go.riyazali.net/httpx?tab=doc#ExecFn) which defines any function capable of executing an `http` transaction (take an `http.Request` and return an `http.Response`). The core library provides two `Execfn` functions, `WithClient(..)` and `WithHandler(..)` (and some variations of those two).\n\nAfter creating the `ExecFn`, you would normally want to call it's [`MakeRequest`](https://pkg.go.dev/go.riyazali.net/httpx?tab=doc#ExecFn.MakeRequest) method, which would allow you to craft an `http.Request` and invoke the corresponding `ExecFn` on it. See [`RequestFactory`](https://pkg.go.dev/go.riyazali.net/httpx?tab=doc#RequestFactory) and [`RequestBuilder`](https://pkg.go.dev/go.riyazali.net/httpx?tab=doc#RequestBuilder) for details on how to craft a custom request, the set of built-in `factories` and `builders` the library provides and how you can write your own!\n\nOnce you've crafted a request, `MakeRequest` would return an [`Assertable`](https://pkg.go.dev/go.riyazali.net/httpx?tab=doc#Assertable) which you could then use to perform _assertions_ on the received `http.Response`. See [`Assertion`](https://pkg.go.dev/go.riyazali.net/httpx?tab=doc#Assertion) for more details.\n\nAnd that's pretty much it! that's the core of the library! roughly `~120` lines of code (give or take :wink:)\n\n### Example\n\nThis example demonstrates how you would use **`httpx`** to make a `GET` request to [`httpbin.org`](https://httbin.org) and carry out assertions on the received `http.Response`.\n\n```golang\nimport (\n  . \"go.riyazali.net/httpx\"\n  . \"go.riyazali.net/httpx/helpers\"\n  \"net/http\"\n  \"testing\"\n)\n\nfunc TestRemote(t *testing.T) {\n  type X struct {\n    Args map[string]string `json:\"args\"`\n  }\n\n  WithDefaultClient().\n    MakeRequest(\n      Get(Url(\"https://httpbin.org/get\", WithQueryParam(\"a\", \"1\"))),\n      WithHeader(\"Accept\", \"application/json\"),\n    ).\n    ExpectIt(t,\n      ToHaveStatus(http.StatusOK),\n      BodyJson(func(x X) error {\n        return Multiple(\n          AssertThat(x.Args[\"a\"] != \"\", \"'a' is empty\"),\n          AssertThat(x.Args[\"b\"] == \"\", \"'b' is present\"),\n        )\n      }),\n    )\n}\n```\n\nFor more examples and samples, make sure to checkout the [`godoc` here](https://pkg.go.dev/go.riyazali.net/httpx)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Friyaz-ali%2Fhttpx","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Friyaz-ali%2Fhttpx","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Friyaz-ali%2Fhttpx/lists"}