QuickApi v0.1.0 QuickApi.Client behaviour View Source
Client responsible for making requests to the API and handling the responses.
This client allows us to define all of our HTTP request logic and configuration in one place so that we can easily change or adapt this away from all of the other business logic of our library.
You can define your own QuickApi Client like so
Example usage
defmodule MyClient do
use QuickApi.Client
def default_headers() do
[{"Authorization", "Brearer MYSUPERSECURETOKEN"}]
end
def api_host() do
"https://example.com"
end
endWe have access to HTTP request types on this client and it will automatically use a base url as well as set all the necessary headers for us.
We have access to GET, POST, PATCH, PUT, and DELETE HTTP requests using this client.
Example usage
QuickApi.Client.get("/path", %{query_param: "value"})
QuickApi.Client.post("/path", %{param1: "value"})
QuickApi.Client.patch("/path", %{param1: "value"})
QuickApi.Client.put("/path", %{param1: "value"})
QuickApi.Client.delete("/path") Link to this section Summary
Callbacks
This is a mandatory callback for the behaviour you need to define to set the api base url
This is an optional callback for the behaviour you can choose to define if you would like to override the default headers. This would be a good place to set others such as the authorization headers for your client that are needed on every request.
Link to this section Callbacks
Specs
api_host() :: String.t()
This is a mandatory callback for the behaviour you need to define to set the api base url
The default functionality is empty headers.
Specs
This is an optional callback for the behaviour you can choose to define if you would like to override the default headers. This would be a good place to set others such as the authorization headers for your client that are needed on every request.
The default functionality is empty headers.