mirror of
https://github.com/lostisland/faraday.git
synced 2025-10-04 00:02:03 -04:00
1.3 KiB
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 theAuthorization
header to theuser:password
base64 representation.Multipart
converts aFaraday::Request#body
hash of key/value pairs into a multipart form request.UrlEncoded
converts aFaraday::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.