Skip to content

Commit

Permalink
Feature/support body get (#201)
Browse files Browse the repository at this point in the history
  • Loading branch information
alfredo-handcash committed Mar 15, 2021
1 parent 356e37f commit 4051a1d
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 0 deletions.
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

0 comments on commit 4051a1d

Please sign in to comment.