read method
Performs a request attempt for a read
route added on the server side
Similar to readStream, but doesn't stream changes.
route
The path of the route.
params
Additional data (optional),
here can be added a filter to indicate to the server
which data will be received.
neverTimeout
Default: false
(optional). If true
: the request attempt will live as long as possible.
If false
: if the request doesn't receive a response within the time limit, it will be canceled. The field requestTimeoutInMs
defined on the server side will be the time limit.
persevere
Default: false
(optional). If persevere
is true
and this route was created in the server with addRouteFor.authenticatedUsers
(requires authentication)
but clearAuthentication() is called, then this route will wait for the authentication to come back.
In case of false
the route will be canceled right after clearAuthentication() is called (only if this route requires authentication).
This is no-op in case this route doesn't require authentication (addRoute.forAllUsers
).
Example
AsklessClient.instance.read(
route: 'allProducts',
params: {
'nameContains' : 'game'
},
neverTimeout: true
).then((res) {
for (final product in List.from(res.output)) {
print(product['name']);
}
});
Implementation
Future<AsklessResponse> read({required String route, Map<String, dynamic>? params, bool neverTimeout = false, bool persevere = false}) async {
await getIt.get<ConnectionService>().waitForConnectionOrTimeout(timeout: neverTimeout ? null : Duration(milliseconds: getIt.get<ConnectionService>().connectionConfiguration.requestTimeoutInMs));
return getIt.get<RequestsService>().runOperationInServer(data: ReadCli(route: route, params: params), neverTimeout: neverTimeout, isPersevere: () => persevere,);
}