Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/matthewoden/elixir-httpbuilder
A DSL for building chainable, composable HTTP requests. API structure taken from the lovely elm-http-builder
https://github.com/matthewoden/elixir-httpbuilder
Last synced: about 1 month ago
JSON representation
A DSL for building chainable, composable HTTP requests. API structure taken from the lovely elm-http-builder
- Host: GitHub
- URL: https://github.com/matthewoden/elixir-httpbuilder
- Owner: matthewoden
- License: mit
- Created: 2017-11-12T04:06:08.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2018-06-16T20:01:41.000Z (over 6 years ago)
- Last Synced: 2024-10-30T15:24:13.527Z (2 months ago)
- Language: Elixir
- Homepage: https://hexdocs.pm/http_builder
- Size: 80.1 KB
- Stars: 15
- Watchers: 1
- Forks: 6
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
![](https://i.imgur.com/4xZNmrH.png)
# HttpBuilder
A DSL for building chainable, composable HTTP requests. API structure taken from
the lovely [elm-http-builder](https://github.com/lukewestby/elm-http-builder).Currently comes with adapters for `HTTPoison`, `HTTPotion`, `Hackney` and
`IBrowse`. JSON parsers are configurable, but defaults to `Poison` if present.Documentation can be found at
[https://hexdocs.pm/http_builder](https://hexdocs.pm/http_builder).It's early days still. Feedback welcome!
## Example Usage
```elixir
defmodule MyApp.APIClient doimport HttpBuilder
@adapter Application.get_env(:my_app, :http_adapter)
def client() do
# Alternatively - use HttpBuilder.cast/1 with a map of options.
HttpBuilder.new()
|> with_host("https://some-api.org")
|> with_adapter(@adapter)
|> with_headers(%{
"Authorization" => "Bearer #{MyApp.getToken()}",
"Content-Type" => "application/json"
})end
def submit_widget(body) do
client()
|> post("/v1/path/to/submit")
|> with_body(body)
|> send()
enddef get_widget do
client()
|> get("/v1/path/to/fetch")
|> with_query_params(%{"offset" => 10, "limit" => 5})
|> with_request_timeout(10 * 1000)
|> with_receive_timeout(5 * 1000)
|> send()
endend
```## Installation
```elixir
def deps do
[
{:http_builder, "~> 0.4.0"}
]
end
```Documentation can be generated with
[ExDoc](https://github.com/elixir-lang/ex_doc) and published on
[HexDocs](https://hexdocs.pm). Once published, the docs can be found at
[https://hexdocs.pm/http_builder](https://hexdocs.pm/http_builder).