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

Feature/support body get #201

Merged
merged 3 commits into from
Mar 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions chopper/lib/src/base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,7 @@ class ChopperClient {
/// Makes a HTTP GET request using the [send] function.
Future<Response<BodyType>> get<BodyType, InnerType>(
String url, {
dynamic body,
Map<String, String> headers,
Map<String, dynamic> parameters,
String baseUrl,
Expand All @@ -358,6 +359,7 @@ class ChopperClient {
HttpMethod.Get,
url,
baseUrl ?? this.baseUrl,
body: body,
headers: headers,
parameters: parameters,
),
Expand Down
24 changes: 24 additions & 0 deletions chopper/test/base_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,30 @@ void main() {
httpClient.close();
});

test('GET with body', () async {
final httpClient = MockClient((request) async {
expect(
request.url.toString(),
equals('$baseUrl/test/get_body'),
);
expect(request.method, equals('GET'));
expect(request.body, equals('get body'));

return http.Response('get response', 200);
});

final chopper = buildClient(httpClient);
final service = chopper.getService<HttpTestService>();

final response =
await service.getBody('get body');

expect(response.body, equals('get response'));
expect(response.statusCode, equals(200));

httpClient.close();
});

test('POST', () async {
final httpClient = MockClient((request) async {
expect(
Expand Down
8 changes: 8 additions & 0 deletions chopper/test/test_service.chopper.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions chopper/test/test_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ abstract class HttpTestService extends ChopperService {
@Query('test') bool test,
});

@Get(path: 'get_body')
Future<Response> getBody(@Body() dynamic body);

@Post(path: 'post')
Future<Response> postTest(@Body() String data);

Expand Down