scrapy_cloud_ex v0.1.2 ScrapyCloudEx.HttpAdapter behaviour View Source

Defines the behaviour used to process the body of API responses.

A module implementing this behaviour can be used for making http calls to API endpoints by using the :http_adapter key in the opts parameter of every endpoint module.

Link to this section Summary

Callbacks

Invoked to process a response from the API

Invoked to make a request to an API endpoint

Link to this section Types

Link to this type error_map() View Source
error_map() :: %{status: integer(), message: any()}

Link to this section Callbacks

Link to this callback handle_response(response, opts) View Source
handle_response(
  response :: ScrapyCloudEx.HttpAdapter.Response.t(),
  opts :: Keyword.t()
) :: {:ok, any()} | {:error, error_map()}

Invoked to process a response from the API.

The body attribute of the response will always be decompressed, even if the API responded with a gzipped reply.

The opts value is a copy of the opts attribute from the ScrapyCloudEx.HttpAdapter.RequestConfig.t/0 provided to request/1.

Invoked to make a request to an API endpoint.

The opts attribute of the ScrapyCloudEx.HttpAdapter.RequestConfig parameter will always have a :decoder value provided, which defaults to ScrapyCloudEx.Decoders.Default.

By default, the headers attribute will contain a {:"Accept-Encoding", "gzip"} value. This header should be sent to the API endpoint if a compressed repsonse is desired. Not all API endpoints support compressed responses, but providing this header to endpoints that don’t support it won’t result in an error. If a compressed response is received, it will be handled and decompressed transparently.