Update README with instructions for use

This commit is contained in:
Mikko Ahlroth 2023-02-17 22:29:25 +02:00
parent 3e71e27e78
commit 061f029bf7

View file

@ -16,3 +16,23 @@ gleam add finch_gleam
``` ```
and its documentation can be found at <https://hexdocs.pm/finch_gleam>. and its documentation can be found at <https://hexdocs.pm/finch_gleam>.
## Usage
```gleam
import gleam/uri
import gleam/http
import gleam/http/request
import gleam/erlang/atom
import finch
assert Ok(url) = uri.parse("https://example.com/")
assert Ok(req) = request.from_uri(url)
let req = request.Request(..req, method: http.Post, body: "foo bar")
// Build Finch request from gleam/http request
let finch_req = finch.build(req, [])
// Run request with Finch, using Finch.Server, returns gleam/http response
assert Ok(resp) = finch.request(finch_req, atom.create_from_string("Elixir.Finch.Server"))
```