Etoex
Etoex — библиотека для последовательного выполнения HTTP-операций (pipeline) с:
assigns+ интерполяция<VAR>в path/bodysave: извлечение значений из ответа по JSONPath (a.b[0].id,[0].id,["a","b",0,"id"])func: динамическая модификация запроса на основе предыдущих результатов-
pluggable
auth(Bearer / Static headers / Stack) иtransport(Tesla / Mock) -
опциональный
draw/3для Livebook (Kino)
Installation
def deps do
[
{:etoex, "~> 0.1"}
]
end
## Quick start
client =
Etoex.client(
base_url: "https://jsonplaceholder.typicode.com",
recv_timeout: 30_000
)ops = [
%{request: {:get, "/posts/1"}, save: %{USER_ID: "userId"}},
%{request: {:get, "/users/<USER_ID>"}}]
= Etoex.run(client, ops) report.assigns report.results
## Auth
### Bearer
client = Etoex.client(
base_url: "https://api.example.com",
auth: {Etoex.Auth.Bearer, token: "TOKEN"})
### Static headers
client = Etoex.client(
base_url: "https://api.example.com",
auth: {Etoex.Auth.StaticHeaders, headers: [{"Authorization", "Bearer TOKEN"}]})
### Stack
client = Etoex.client(
base_url: "https://api.example.com",
auth: {Etoex.Auth.Stack, auths: [
{Etoex.Auth.Bearer, token: "TOKEN"},
{Etoex.Auth.StaticHeaders, headers: %{"X-Trace-Id" => "abc"}}
]})
### TLS
client.tls прокидывается в hackney как ssl_options.
Пример (если используешь certifi в своём приложении):
client = Etoex.client(
base_url: "https://api.example.com",
tls: [verify: :verify_peer, cacertfile: :certifi.cacertfile()])
### Livebook (Kino)
Etoex.draw(client, ops)
### Integration tests
По умолчанию внешняя сеть выключена:
mix test mix test --include integration