Skip to content

Commit

Permalink
docs(README): added relative API baseUrl section (#640)
Browse files Browse the repository at this point in the history
  • Loading branch information
KernelPanic92 authored Nov 30, 2023
1 parent c21ba9f commit 0e64527
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,27 @@ client.getTask('2').then((it) {
}
});
```

### Relative API baseUrl

If you want to use a relative `baseUrl` value in the `RestApi` annotation of the `RestClient`, you need to specify a `baseUrl` in `dio.options.baseUrl`.

```dart
@RestApi(baseUrl: '/tasks')
abstract class RestClient {
factory RestClient(Dio dio, {String baseUrl}) = _RestClient;
@GET('{id}')
Future<HttpResponse<Task>> getTask(@Path('id') String id);
@GET('')
Future<HttpResponse<List<Task>>> getTasks();
}
dio.options.baseUrl = 'https://5d42a6e2bc64f90014a56ca0.mockapi.io/api/v1';
final client = RestClient(dio);
```

### Multiple endpoints support

If you want to use multiple endpoints to your `RestClient`, you should pass your base url when you initiate `RestClient`. Any value defined in `RestApi` will be ignored.
Expand Down

0 comments on commit 0e64527

Please sign in to comment.