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

added optional body to delete #439

Merged
merged 6 commits into from
Jan 8, 2021
Merged

added optional body to delete #439

merged 6 commits into from
Jan 8, 2021

Conversation

j4nk3e
Copy link
Contributor

@j4nk3e j4nk3e commented Jul 3, 2020

As requested in issues
#383
and
#206

@benedictjohannes
Copy link

MDN has stated that HTTP DELETE method may contain request body. Any reason this PR is not merged?

This PR looks good to go apart of merge conflicts.

@j4nk3e
Copy link
Contributor Author

j4nk3e commented Aug 23, 2020

I updated the PR to resolve the conflict.

Copy link

@benedictjohannes benedictjohannes left a comment

Choose a reason for hiding this comment

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

(deleted comment -- moved to inline code comment)

lib/src/base_client.dart Outdated Show resolved Hide resolved
@j4nk3e
Copy link
Contributor Author

j4nk3e commented Aug 24, 2020

As @benedictjohannes suggested, I also added the additional parameters to the global function and abstract Client class, as opposed to only the BaseClient in the last commit.

@kevmoo kevmoo requested a review from natebosch August 24, 2020 18:26
Copy link

@benedictjohannes benedictjohannes left a comment

Choose a reason for hiding this comment

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

So far it looks good, I'd vouch for this PR being merged

lib/http.dart Outdated
Future<Response> delete(url, {Map<String, String> headers}) =>
_withClient((client) => client.delete(url, headers: headers));
Future<Response> delete(url,
{Map<String, String> headers, body, Encoding encoding}) =>

Choose a reason for hiding this comment

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

Could you tell me please, what is the exact type definition for the body?

Choose a reason for hiding this comment

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

I can directly send a Map to body, which tries to convert it to (JSON) String, or String. The body field work the same across HTTP verb methods, where it's not included in the GET or OPTION as these verbs doesn't support request body and inside it. Meanwhile, DELETE does support body, hence this pull request.

You can observe that type definition for body isn't also referenced in other methods in this file. Hence my support for this PR

Copy link
Member

Choose a reason for hiding this comment

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

We lack documentation of the body parameter on the other similar methods too, and the documentation in general isn't amazing, so we should give it an overhaul soon.
No need to do anything special here, it's the same body as all the other body parameters.

Choose a reason for hiding this comment

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

Do you have plans regarding the documentation overhaul? If you share your plans the community might be able to help.

@leecommamichael
Copy link

leecommamichael commented Oct 8, 2020

Please let this be merged. It was a huge context switch to go all the way from my editor to this PR when I found out client.delete has a different signature than the other HTTP methods. There will be, and have been, so many people like me.

@benedictjohannes
Copy link

@natebosch can you please review and/or merge this? Its been a while.

@natebosch
Copy link
Member

We've had this request a few times so far, and each time we push back against the idea of adding an argument that should almost never be used. Especially since there is an existing workaround of using client.send and constructing the request manually. As a general principle we prefer to support the common case directly, and uncommon cases with workarounds, so that we don't clutter the common API with uncommon complexity.

The big thing was it is also a breaking change.

Our current situation might push us to adopt this API:

  • The complexity cost is fairly low, especially since, as was mentioned in this thread, adding the argument makes this match other similar methods.
  • This seems to be coming up frequently.
  • The big one - we are about to make a breaking version change anyway for the migration to null safety.

cc @lrhn in case you have any thoughts or feel strongly that we shouldn't do this.

I think I'm leaning towards getting this updated and merged. It will take a bit of time to verify that I can get it landed without breaking internal users or the SDK.

@natebosch natebosch self-assigned this Dec 11, 2020
@benedictjohannes
Copy link

@natebosch This does not look like it will break API compatibility since the body parameter is optional. IMHO body in DELETE the fact that HTTP spec does support it should be enough to make the go-to HTTP handler in any language (this package) to support it. PPS: I've seen several API expects body in DELETE, and I develop (backend) applications with this pattern.

@lrhn
Copy link
Member

lrhn commented Dec 11, 2020

The top-level on is definitely non-breaking. The instance method is not something I would consider a breaking change. Nobody else is intended or expected to implement the interface. This is a tool package, intended to be used as-is.

Adding it during a major version increment makes it doubly not breaking, so if it's a change we do want, now is definitely the time to do it.

I think it's a fine addition, and I'm fine adding it now.

@natebosch
Copy link
Member

The instance method is not something I would consider a breaking change. Nobody else is intended or expected to implement the interface. This is a tool package, intended to be used as-is.

The interface is specifically designed for extending or implementing.

http/README.md

Lines 49 to 52 in d473635

This package is designed to be composable. This makes it easy for external
libraries to work with one another to add behavior to it. Libraries wishing to
add behavior should create a subclass of [BaseClient][] that wraps another
[Client][] and adds the desired behavior:

I think it's a fine addition, and I'm fine adding it now.

There are at least a few implementations of this class, though I need to check whether any override this method. Please wait to add this until we get things prepped.

@natebosch natebosch removed their assignment Jan 5, 2021
@natebosch natebosch requested a review from jakemac53 January 5, 2021 23:25
@natebosch natebosch merged commit 3845753 into dart-lang:master Jan 8, 2021
@natebosch
Copy link
Member

Thanks everyone for the contributions and discussion!

This will roll out once we are ready to publish the null safety migration for this package. #501

idabgsram pushed a commit to idabgsram/flutter_http_legacy that referenced this pull request Jun 2, 2021
The spec discourages but does not forbid a body. Allow a body argument
without falling back on the `send` API since some servers may be
designed specifically to require it.

Closes dart-lang#383, closes dart-lang#206
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants