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
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/http.dart
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,10 @@ Future<Response> patch(url,
/// the same server, you should use a single [Client] for all of those requests.
///
/// For more fine-grained control over the request, use [Request] instead.
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.

_withClient((client) =>
client.delete(url, headers: headers, body: body, encoding: encoding));

/// Sends an HTTP GET request with the given headers to the given URL, which can
/// be a [Uri] or a [String], and returns a Future that completes to the body of
Expand Down
6 changes: 4 additions & 2 deletions lib/src/base_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@ abstract class BaseClient implements Client {
_sendUnstreamed('PATCH', url, headers, body, encoding);

@override
Future<Response> delete(url, {Map<String, String> headers}) =>
_sendUnstreamed('DELETE', url, headers);
Future<Response> delete(url,
{Map<String, String> headers, body, Encoding encoding}) =>
_sendUnstreamed('DELETE', url, headers, body, encoding);

@override
Future<String> read(url, {Map<String, String> headers}) async {
final response = await get(url, headers: headers);
Expand Down
3 changes: 2 additions & 1 deletion lib/src/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ abstract class Client {
/// which can be a [Uri] or a [String].
///
/// For more fine-grained control over the request, use [send] instead.
Future<Response> delete(url, {Map<String, String> headers});
Future<Response> delete(url,
{Map<String, String> headers, body, Encoding encoding});

/// Sends an HTTP GET request with the given headers to the given URL, which
/// can be a [Uri] or a [String], and returns a Future that completes to the
Expand Down