Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deletes with bodies #693

Closed
Carlbc18 opened this issue May 17, 2017 · 23 comments
Closed

Deletes with bodies #693

Carlbc18 opened this issue May 17, 2017 · 23 comments
Labels
Projects
Milestone

Comments

@Carlbc18
Copy link

Carlbc18 commented May 17, 2017

HTTP spec has changed in 2014 and allows for deletes to have bodies. Is there a plan in place to resolve your delegator method in connection.rb to allow for a body with the delete method and not nil'ing it out?

@Carlbc18
Copy link
Author

A PR will be up shortly for your review.

@iMacTia
Copy link
Member

iMacTia commented May 17, 2017

Hi @Carlbc18,

could you please provide a link to the above changes?
I guess that's only true for HTTP 2.0 specs, so we might need to consider this feature carefully.

@Carlbc18
Copy link
Author

Carlbc18 commented May 17, 2017

https://tools.ietf.org/html/rfc7231#section-4.3.5

FYI: This same block of text applies to GET && HEAD requests as well.

specifically this part of the spec:

A payload within a DELETE request message has no defined semantics;
sending a payload body on a DELETE request might cause some existing
implementations to reject the request.

@Carlbc18
Copy link
Author

Carlbc18 commented May 17, 2017

i have a code change with tests that works (not sure if you want it). how do i create a pr for this project?

@Carlbc18
Copy link
Author

I guess that's only true for HTTP 2.0 specs, so we might need to consider this feature carefully.

this is actually part of HTTP 1.1

@iMacTia
Copy link
Member

iMacTia commented May 17, 2017

I would definitely consider it if you want to create a PR.
You can do it as with any other repo, simply fork faraday and apply the changes on your fork, then create a PR to our master branch.

@Carlbc18
Copy link
Author

Thanks @iMacTia. I'll put it up. Whats your views on changing the version finally have a major version number with this? This change could be breaking for many. I'd like to follow semver pattern, and version faraday to be 1.0.0 at this point. Let me know your thoughts.

@iMacTia
Copy link
Member

iMacTia commented May 19, 2017

We're definitely trying to stick to semver and we've v1.0 scheduled with some breaking changes.
If this change is gonna break backward compatibility, then it will be released only in version 1.0 (which currently doesn't have a fixed release date).
However, my understanding is that you should now be able to OPTIONALLY add a body to GET, HEAD and DELETE requests, so shouldn't that be backward compatible? Am I missing something?

@Carlbc18
Copy link
Author

@iMacTia i versioned to 0.13.0 and the PR is up. We can take any other conversation around this to the PR as i'm sure there will be comments. Thanks again!

@iMacTia
Copy link
Member

iMacTia commented May 31, 2017

This is a follow up on my #695 (comment).
First of all we should decide HOW we would like this to work.
Assuming changes should be backward compatible, the below should still work:

conn = Faraday.new(...)
conn.get('/path', {page: 1, per: 10})

# performs "GET /path?page=1&per=10"

Option 1 as stated in my comment would be to make this behaviour configurable:

conn = Faraday.new(..., standard: :http1_1)
conn.get('/path', {page: 1, per: 10})

# performs "GET /path" with body "page=1&per=10" (assuming www_form_url_encoded request)

Option 2 instead would mean something more powerful:

conn = Faraday.new(...) # note no special config here
conn.get('/path', {page: 1, per: 10}, body: {some_key: 'some_value')

# performs "GET /path?page=1&per=10" with body "some_key=some_value"

@iMacTia
Copy link
Member

iMacTia commented May 31, 2017

There's an issue though, option 2 might only work with ruby >= 2 as ruby 1.9 doesn't support keyword params 😞

@Carlbc18
Copy link
Author

I think in regards to this not working on ruby 1.9 I feel like that is ok. Ruby 1.9 is many years old. I'd advocate we version bump to at least 2.0 for minimum ruby version, which would go inline with a v1.0 release of Faraday. Also option 2 more closely follows http 1.1 spec in my opinion as you'd have the option to pass parms and or a optional body.

I feel like attempting to maintain backwards compatibility with a http spec feature that does work with ruby 1.9 is going to cause problems. I think this feature would be better suited for V1 of Faraday. I feel like there are too many variables were needing to support for this change (ruby v, params passing). Maybe I'm overthinking....

@iMacTia
Copy link
Member

iMacTia commented Jun 1, 2017

I think in regards to this not working on ruby 1.9 I feel like that is ok. Ruby 1.9 is many years old. I'd advocate we version bump to at least 2.0 for minimum ruby version, which would go inline with a v1.0 release of Faraday. Also option 2 more closely follows http 1.1 spec in my opinion as you'd have the option to pass parms and or a optional body.

I totally agree with al the above. That's indeed the best course of action, even though this means we'll still have to wait for v1.0

@iMacTia
Copy link
Member

iMacTia commented Jun 1, 2017

So to define a v1.0 backward compatible API, we could attempt the following:

GET, HEAD, DELETE REQUESTS

conn = Faraday.new(...) # note no special config here
conn.get(path, url_params, body: {...})
# second parameter is URL PARAMS, optionally accept a named parameter for request body
# works the same for head and delete

POST, PUT, PATCH REQUESTS

conn = Faraday.new(...) # note no special config here
conn.post(path, body, url_params: {...})
# second parameter is REQUEST BODY, optionally accept a named parameter for url_params
# works the same for put and patch

I think this way we're covering every possible combination and extending post/put/patch requests as well!

@Carlbc18
Copy link
Author

Carlbc18 commented Jun 1, 2017

Definitely agree. Do we want to decline my PR and open a new one for this? Is there a V1 branch cut we can work off of?

@iMacTia
Copy link
Member

iMacTia commented Jun 2, 2017

Happy to close that one and start from scratch as it will be completely different. Sorry for that!

I'll create a V1 branch before merging in so feel free to start from master and I'll redirect the PR :)

@iMacTia
Copy link
Member

iMacTia commented Jun 6, 2017

Hi @Carlbc18 just wanted to let you know that branch 1.0 is now available for you 😃.

@iMacTia iMacTia added this to the v1.0 milestone Jun 6, 2017
@Carlbc18
Copy link
Author

Carlbc18 commented Jun 6, 2017

Thank you, thank you! 😀

@HusseinElMotayam
Copy link

For anyone still waiting on this, I found the following workaround which seems to work in my case:

conn = Faraday.new
body = {
some_key: 'some value'
}
conn.run_request(:delete, url, body, headers)

I hope this helps someone until delete no longer nils the body by default

@thaiden
Copy link

thaiden commented Dec 27, 2018

So is there any update on when this will be available?

@iMacTia
Copy link
Member

iMacTia commented Dec 28, 2018

I haven't seen any PR yet, but works on v1 are slowly progressing.
I might be able to work on this myself but I can't give an estimate at the moment.
The updated API on how requests should work is explained on my comment above, so if anyone wants to have a shot at it before me, a PR is very welcome.

For a fully backwards compatible solution, the PR can be branched out of master, and I can make another 0.x release.
If the change is going to break backwards compatibility then it's better to branch out of 1.0 branch

@iMacTia iMacTia moved this from To Do to In progress in v1.0 Feb 20, 2019
@technoweenie
Copy link
Member

#855 is a draft PR to support this.

@technoweenie
Copy link
Member

I'm rejecting this feature. You can use the block form in Faraday to make a request with a body:

conn.delete(url) do |req|
  req.body = { some_key: 'some value' }
end

This idea would have made simple deletes with bodies a single one liner, but the implementation adds more complexity and surprising behavior than I'd like. This block form works great in Faraday already. I prefer modifying properties on a class to adding more arguments to a method:

conn.delete('/foo/1') do |req|
  req.headers["X-Men"] = "marvel"
  req.params[:confirm] = 1
  req.body = { some_key: 'some value' }
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
No open projects
v1.0
Done
Development

No branches or pull requests

5 participants