Services topic
Services
Available Service classes
- HttpService helps you reduce boilerplate when using http client to make http services.
- RestService helps you reduce boilerplate for writing service classes for rest http clients.
RestService
Create service using RestService.
class TodoService extends RestService {
TodoService(http.Client client)
: super(client, builder: (client) {
return RequestClient(
client,
url: Uri(path: '/todos'),
);
});
Future<TodoModel?> getTodo(int id) {
return client.get(Uri(path: '$id')).dataAsync();
}
Future<List<TodoModel>?> getTodos() {
return client.get(Uri()).dataAsync();
}
}
More detailed example: Request Client Example
Classes
-
HttpService<
T extends Client> Get started Configuration Services - A service that uses client for making requests. It is recommend to extend this class and add your method and use the client to make requests in the methods to the server.
- RestService Get started Configuration Services
- A service that can be used to make requests to a JSON Api. It wraps the client with RestClient if necessary to return a RestResponse. It is recommended to extend this class and add your methods to it where you use client to make requests.