Packages
tesla
1.18.0
1.20.0
1.18.3
1.18.2
1.18.1
1.18.0
1.17.0
1.16.0
1.15.3
1.15.2
1.15.1
1.15.0
1.14.3
1.14.2
1.14.1
1.14.0
1.13.2
1.13.1
1.13.0
1.12.3
1.12.2
1.12.1
1.12.0
1.11.2
1.11.1
1.11.0
1.10.3
1.10.2
1.10.1
1.10.0
1.9.0
1.8.1
retired
1.8.0
1.7.0
1.6.1
1.6.0
1.5.1
1.5.0
1.4.4
1.4.3
1.4.2
1.4.1
1.4.0
1.3.3
1.3.2
1.3.1
1.3.0
1.2.1
1.2.0
1.1.0
1.0.0
1.0.0-beta.1
0.10.0
0.9.0
0.8.0
0.7.2
0.7.1
0.7.0
0.6.0
0.5.2
0.5.1
0.5.0
0.3.6
0.3.5
0.3.4
0.3.3
0.3.2
0.3.1
0.2.2
0.2.1
0.1.5
0.1.4
0.1.3
0.1.2
0.1.1
0.1.0
HTTP client library, with support for middleware and multiple adapters.
Security advisory:
This version has known vulnerabilities.
View advisories
Current section
Files
Jump to
Current section
Files
lib/tesla/env.ex
defmodule Tesla.Env do
@moduledoc """
This module defines a `t:Tesla.Env.t/0` struct that stores all data related to request/response.
"""
@type client :: Tesla.Client.t()
@type method :: :head | :get | :delete | :trace | :options | :post | :put | :patch
@typedoc """
Request URL or request target.
Examples:
- `"https://www.google.com"`
- `"/users/1"` when used with `Tesla.Middleware.BaseUrl`
Callers are expected to pass a valid, already-encoded URL or request target.
`Tesla` does not automatically validate, normalize, or percent-encode the URL path.
Some middleware may rewrite `env.url`.
"""
@type url :: binary
@type query_key :: binary | atom
@type query_scalar :: String.Chars.t()
@type query_scalar_list :: [query_scalar]
@type query_pair :: {query_key, param}
@type query_list :: [query_pair]
@type query_string :: Tesla.OpenAPI.QueryString.t()
@type param :: query_scalar | query_scalar_list | query_list | %{optional(query_key) => param}
@typedoc """
Structured query params as a list or map, including nested maps.
## Examples
- `[{"param", "value"}]` will be translated to `?param=value`.
- `%{filters: %{page: 1}}` will be translated to `?filters%5Bpage%5D=1`
(that is, `filters[page]` with brackets percent-encoded by default).
Map query params do not guarantee encoded parameter order when Tesla's default
URL builder encodes them directly. In `Tesla.Middleware.Query` `:modern` mode,
values matching `Tesla.OpenAPI.QueryParams` definitions are encoded in definition
order.
A `t:Tesla.OpenAPI.QueryString.t/0` value represents the entire URL query string and
must not be mixed with normal query params.
"""
@type query :: query_list | query_string | %{optional(query_key) => param}
@type headers :: [{binary, binary}]
@type body :: any
@type status :: integer | nil
@type opts :: keyword
@type runtime :: {atom, atom, any} | {atom, atom} | {:fn, (t -> t)} | {:fn, (t, stack -> t)}
@type stack :: [runtime]
@type result :: {:ok, t()} | {:error, any}
@type assigns :: %{optional(atom) => any}
@type private :: %{optional(atom) => any}
@typedoc """
Request/response state carried through the middleware pipeline.
## Fields
* `:method` - method of request. Example: `:get`.
* `:url` - request URL. Example: `"https://www.google.com"`.
* `:query` - structured query params. See `t:query/0`.
Query params passed in the URL, such as `"/get?param=value"`, are not
parsed to the `:query` field.
* `:headers` - list of request/response headers.
Example: `[{"content-type", "application/json"}]`.
Request headers are overridden by response headers when the adapter is called.
* `:body` - request/response body.
Request body is overridden by response body when the adapter is called.
* `:status` - response status. Example: `200`.
* `:opts` - list of options. Example: `[adapter: [recv_timeout: 30_000]]`.
* `:assigns` - user data as a map for application-specific metadata.
* `:private` - data reserved for libraries and middleware. Keys must be
atoms. Prefix keys with the name of your project to avoid conflicts.
The `tesla_` prefix is reserved for Tesla.
"""
@type t :: %__MODULE__{
method: method,
query: query,
url: url,
headers: headers,
body: body,
status: status,
opts: opts,
assigns: assigns,
private: private,
__module__: atom() | nil,
__client__: client() | nil
}
defstruct method: nil,
url: "",
query: [],
headers: [],
body: nil,
status: nil,
opts: [],
assigns: %{},
private: %{},
__module__: nil,
__client__: nil
end