Skip to content

Move json middleware (request and response) from faraday_middleware#1300

Merged
iMacTia merged 6 commits intomainfrom
move-json-middleware
Aug 9, 2021
Merged

Move json middleware (request and response) from faraday_middleware#1300
iMacTia merged 6 commits intomainfrom
move-json-middleware

Conversation

@iMacTia
Copy link
Copy Markdown
Member

@iMacTia iMacTia commented Aug 7, 2021

Description

The JSON middleware, both request and response ones, are between the most used and require no external dependency since the json module is part of Ruby.
For this reason, we can safely move it inside Faraday.

Tests have also been moved and the Website documentation have been updated.

Todos

List any remaining work that needs to be done, i.e:

  • Tests
  • Documentation

@iMacTia iMacTia requested a review from olleolleolle August 7, 2021 18:29
@iMacTia iMacTia self-assigned this Aug 7, 2021
@olleolleolle
Copy link
Copy Markdown
Member

Ruby 3 seems to have some unwanted behaviour about arguments, is that around kwargs?

@iMacTia
Copy link
Copy Markdown
Member Author

iMacTia commented Aug 8, 2021

It's the dependency loader, even adding ** to the middleware initializer in the spec doesn't solve the problem completely. I was planning to get rid of it anyway so I'll do that in another PR

@iMacTia
Copy link
Copy Markdown
Member Author

iMacTia commented Aug 8, 2021

I'm gonna finish this up once #1301 gets merged 👍

Copy link
Copy Markdown
Member

@olleolleolle olleolleolle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wonderful!

Comment thread docs/middleware/list.md Outdated
Comment thread docs/middleware/request/instrumentation.md Outdated
Comment thread docs/middleware/request/json.md Outdated
Comment thread docs/middleware/request/json.md Outdated
Comment thread docs/middleware/request/json.md Outdated
Comment thread docs/middleware/response/logger.md Outdated
Comment thread lib/faraday/request.rb
self.headers = serialised[:headers]
self.path = serialised[:path]
self.params = serialised[:params]
self.options = serialised[:options]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this change!

Comment thread lib/faraday/request/json.rb Outdated

def process_request?(env)
type = request_type(env)
body?(env) && (type.empty? || MIME_TYPE_REGEX =~ type)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ruby version question: Can we use #match? here?

Comment thread lib/faraday/response/json.rb Outdated
def process_response_type?(env)
type = response_type(env)
@content_types.empty? || @content_types.any? do |pattern|
pattern.is_a?(Regexp) ? type =~ pattern : type == pattern
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, perhaps too, an opportunity for #match?

Comment thread spec/faraday/response/json_spec.rb Outdated
let(:options) { {} }
let(:headers) { {} }
let(:middleware) do
puts options
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is debug output, perhaps it can be removed?

Copy link
Copy Markdown
Member

@olleolleolle olleolleolle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me!

@iMacTia iMacTia merged commit 4b6162d into main Aug 9, 2021
@iMacTia iMacTia deleted the move-json-middleware branch August 9, 2021 07:52
iMacTia added a commit that referenced this pull request Feb 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants