iMacTia 66384d32dd Merges #970.
Adds table of content to homepage.
Adds details page for logger middleware.
2019-05-19 17:41:27 +01:00

1.3 KiB

layout title permalink hide
page Middleware Usage /middleware true

A Faraday::Connection uses a Faraday::RackBuilder to assemble a Rack-inspired middleware stack for making HTTP requests. Each middleware runs and passes an Env object around to the next one. After the final middleware has run, Faraday will return a Faraday::Response to the end user.

Middleware Types

Request

Request middleware can modify Request details before the Adapter runs. Most middleware set Header values or transform the request body based on the content type.

  • BasicAuthentication sets the Authorization header to the user:password base64 representation.
  • Multipart converts a Faraday::Request#body hash of key/value pairs into a multipart form request.
  • UrlEncoded converts a Faraday::Request#body hash of key/value pairs into a url- encoded request body.
  • Retry automatically retries requests that fail due to intermittent client or server errors (such as network hiccups).

Response

Response middleware receives the response from the adapter and can modify its details before returning it.

  • Logger logs both the request and the response body and headers.
  • RaiseError checks the response HTTP code and raises an exception if not in the 2xx range.