{"id":16655363,"url":"https://github.com/zhongwencool/maxwell","last_synced_at":"2025-04-05T13:08:12.432Z","repository":{"id":45413199,"uuid":"54479028","full_name":"zhongwencool/maxwell","owner":"zhongwencool","description":"Maxwell is an HTTP client which support for middleware and multiple adapters.","archived":false,"fork":false,"pushed_at":"2023-12-19T03:15:41.000Z","size":341,"stargazers_count":110,"open_issues_count":8,"forks_count":17,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-03-29T13:58:44.674Z","etag":null,"topics":["hackney","http","http-client","httpc","ibrowse","middleware","wrapper"],"latest_commit_sha":null,"homepage":null,"language":"Elixir","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/zhongwencool.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2016-03-22T13:53:05.000Z","updated_at":"2024-10-27T03:28:34.000Z","dependencies_parsed_at":"2024-06-19T05:30:57.250Z","dependency_job_id":null,"html_url":"https://github.com/zhongwencool/maxwell","commit_stats":{"total_commits":168,"total_committers":17,"mean_commits":9.882352941176471,"dds":"0.39880952380952384","last_synced_commit":"f7b2b40cf43c20700a63dcd438cfc20b5ca8ca55"},"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhongwencool%2Fmaxwell","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhongwencool%2Fmaxwell/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhongwencool%2Fmaxwell/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhongwencool%2Fmaxwell/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zhongwencool","download_url":"https://codeload.github.com/zhongwencool/maxwell/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247339158,"owners_count":20923014,"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":["hackney","http","http-client","httpc","ibrowse","middleware","wrapper"],"created_at":"2024-10-12T09:52:44.682Z","updated_at":"2025-04-05T13:08:12.398Z","avatar_url":"https://github.com/zhongwencool.png","language":"Elixir","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Maxwell\n\n[![Build Status](https://travis-ci.org/zhongwencool/maxwell.svg?branch=master)](https://travis-ci.org/zhongwencool/maxwell)\n[![Inline docs](http://inch-ci.org/github/zhongwencool/maxwell.svg)](http://inch-ci.org/github/zhongwencool/maxwell)\n[![Coveralls Coverage](https://img.shields.io/coveralls/zhongwencool/maxwell.svg)](https://coveralls.io/github/zhongwencool/maxwell)\n[![Module Version](https://img.shields.io/hexpm/v/maxwell.svg)](https://hex.pm/packages/maxwell)\n[![Hex Docs](https://img.shields.io/badge/hex-docs-lightgreen.svg)](https://hexdocs.pm/maxwell/)\n[![Total Download](https://img.shields.io/hexpm/dt/maxwell.svg)](https://hex.pm/packages/maxwell)\n[![License](https://img.shields.io/hexpm/l/maxwell.svg)](https://github.com/zhongwencool/maxwell/blob/master/LICENSE)\n[![Last Updated](https://img.shields.io/github/last-commit/zhongwencool/maxwell.svg)](https://github.com/zhongwencool/maxwell/commits/master)\n\n\nMaxwell is an HTTP client that provides a common interface over [:httpc](http://erlang.org/doc/man/httpc.html), [:ibrowse](https://github.com/cmullaparthi/ibrowse), [:hackney](https://github.com/benoitc/hackney).\n\n## Getting Started\n\nThe simplest way to use Maxwell is by creating a module which will be your API wrapper, using `Maxwell.Builder`:\n\n```elixir\ndefmodule GitHubClient do\n  # Generates `get/1`, `get!/1`, `patch/1`, `patch!/1` public functions\n  # You can omit the list and functions for all HTTP methods will be generated\n  use Maxwell.Builder, ~w(get patch)a\n\n  # For a complete list of middlewares, see the docs\n  middleware Maxwell.Middleware.BaseUrl, \"https://api.github.com\"\n  middleware Maxwell.Middleware.Headers, %{\"content-type\" =\u003e \"application/vnd.github.v3+json\", \"user-agent\" =\u003e \"zhongwenool\"}\n  middleware Maxwell.Middleware.Opts,    connect_timeout: 3000\n  middleware Maxwell.Middleware.Json\n  middleware Maxwell.Middleware.Logger\n\n  # adapter can be omitted, and the default will be used (currently :ibrowse)\n  adapter Maxwell.Adapter.Hackney\n\n  # List public repositories for the specified user.\n  def user_repos(username) do\n    \"/users/#{username}/repos\"\n    |\u003e new()\n    |\u003e get()\n  end\n\n  # Edit owner repositories\n  def edit_repo_desc(owner, repo, name, desc) do\n    \"/repos/#{owner}/#{repo}\"\n    |\u003e new()\n    |\u003e put_req_body(%{name: name, description: desc})\n    |\u003e patch()\n  end\nend\n```\n\n`Maxwell.Builder` injects functions for all supported HTTP methods, in two flavors, the first (e.g. `get/1`) will\nreturn `{:ok, Maxwell.Conn.t}` or `{:error, term, Maxwell.Conn.t}`. The second (e.g. `get!/1`) will return\n`Maxwell.Conn.t` *only* if the request succeeds and returns a 2xx status code, otherwise it will raise `Maxwell.Error`.\n\nThe same functions are also exported by the `Maxwell` module, which you can use if you do not wish to define a wrapper\nmodule for your API, as shown below:\n\n```elixir\niex(1)\u003e alias Maxwell.Conn\niex(2)\u003e Conn.new(\"http://httpbin.org/drip\") |\u003e\n    Conn.put_query_string(%{numbytes: 25, duration: 1, delay: 1, code: 200}) |\u003e\n    Maxwell.get\n{:ok,\n %Maxwell.Conn{method: :get, opts: [], path: \"/drip\",\n  query_string: %{code: 200, delay: 1, duration: 1, numbytes: 25},\n  req_body: nil, req_headers: %{}, resp_body: '*************************',\n  resp_headers: %{\"access-control-allow-credentials\" =\u003e \"true\",\n    \"access-control-allow-origin\" =\u003e \"*\",\n    \"connection\" =\u003e \"keep-alive\",\n    \"content-length\" =\u003e \"25\",\n    \"content-type\" =\u003e \"application/octet-stream\",\n    \"date\" =\u003e \"Sun, 18 Dec 2016 14:32:38 GMT\",\n    \"server\" =\u003e \"nginx\"}, state: :sent, status: 200,\n  url: \"http://httpbin.org\"}}\n```\n\nThere are numerous helper functions for the `Maxwell.Conn` struct. See it's module docs\nfor a list of all functions, and detailed info about how they behave.\n\n## Installation\n\n1.  Add maxwell to your list of dependencies in `mix.exs`:\n\n    ```ex\n    def deps do\n      [{:maxwell, \"~\u003e 2.3\"}]\n    end\n    ```\n\n2.  Ensure maxwell has started before your application:\n\n    ```ex\n    def application do\n       [applications: [:maxwell]] # also add your adapter(ibrowse, hackney)\n    end\n    ```\n\n## Adapters\n\nMaxwell has support for different adapters that do the actual HTTP request processing.\n\n### httpc\n\nMaxwell has built-in support for the [httpc](http://erlang.org/doc/man/httpc.html) Erlang HTTP client.\n\nTo use it simply place `adapter Maxwell.Adapter.Httpc` in your API client definition.\n\n### ibrowse\n\nMaxwell has built-in support for the [ibrowse](https://github.com/cmullaparthi/ibrowse) Erlang HTTP client.\n\nTo use it simply place `adapter Maxwell.Adapter.Ibrowse` in your API client definition.\n\n**NOTE**: Remember to include `:ibrowse` in your applications list.\n\n### hackney\n\nMaxwell has built-in support for the [hackney](https://github.com/benoitc/hackney) Erlang HTTP client.\n\nTo use it simply place `adapter Maxwell.Adapter.Hackney` in your API client definition.\n\n**NOTE**: Remember to include `:hackney` in your applications list.\n\n## Built-in Middleware\n\n### Maxwell.Middleware.BaseUrl\n\nSets the base url for all requests.\n\n### Maxwell.Middleware.Headers\n\nSets default headers for all requests.\n\n### Maxwell.Middleware.HeaderCase\n\nEnforces that all header keys share a specific casing style, e.g. lower-case,\nupper-case, or title-case.\n\n### Maxwell.Middleware.Opts\n\nSets adapter options for all requests.\n\n### Maxwell.Middleware.Rels\n\nDecodes rel links in the response, and places them in the `:rels` key of the `Maxwell.Conn` struct.\n\n### Maxwell.Middleware.Logger\n\nLogs information about all requests and responses. You can set `:log_level` to log the information at that level.\n\n### Maxwell.Middleware.Json\n\nEncodes all requests as `application/json` and decodes all responses as `application/json`.\n\n### Maxwell.Middleware.EncodeJson\n\nEncodes all requests as `application/json`.\n\n### Maxwell.Middleware.DecodeJson\n\nDecodes all responses as `application/json`.\n\n**NOTE**: The `*Json` middlewares require [Poison](https://github.com/devinus/poison) as dependency, versions 2.x and 3.x are supported.\nYou may provide your own encoder/decoder by providing the following options:\n\n```ex\n# For the EncodeJson module\nmiddleware Maxwell.Middleware.EncodeJson,\n  encode_content_type: \"text/javascript\",\n  encode_func: \u0026other_json_lib.encode/1]\n\n# For the DecodeJson module\nmiddleware Maxwell.Middleware.DecodeJson,\n  decode_content_types: [\"yourowntype\"],\n  decode_func: \u0026other_json_lib.decode/1]\n\n# Both sets of options can be provided to the Json module\n```\n\n## Custom Middlewares\n\nTake a look at the [Maxwell.Middleware](https://github.com/zhongwencool/maxwell/blob/master/lib/maxwell/middleware/middleware.ex) for more information\non the behaviour. For example implementations take a look at any of the middleware modules in the repository.\n\n## Contributing\n\nContributions are more than welcome!\n\nCheck the issues tracker for anything marked \"help wanted\", and post a comment that you are planning to begin working on the issue. We can\nthen provide guidance on implementation if necessary.\n\n## License\n\nSee the [LICENSE](https://github.com/zhongwencool/maxwell/blob/master/LICENSE) file for license rights and limitations (MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzhongwencool%2Fmaxwell","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzhongwencool%2Fmaxwell","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzhongwencool%2Fmaxwell/lists"}