lostisland / faraday

Simple, but flexible HTTP client library, with support for multiple backends.
https://lostisland.github.io/faraday
MIT License
5.73k stars 976 forks source link

Configurable JSON encoders and decoders #1539

Closed ne006 closed 9 months ago

ne006 commented 9 months ago

Moves lostisland/faraday_middleware/#286

By default Faraday::Request::Json and Faraday::Response::Json use json to encode/decode JSON data, although there are gems like oj which do the job faster than Ruby's built-in json.

This implementation allows to pass encoder option to Faraday::Request::Json and decoder option to pass in parser_options to Faraday::Response::Json

require 'oj'

Faraday.new do |f|
  f.request :json, encoder: Oj
  f.response :json, parser_options: { decoder: Oj }
end