create method

Future<AsklessResponse> create({
  1. required String route,
  2. required dynamic body,
  3. Map<String, dynamic>? params,
  4. bool neverTimeout = false,
  5. bool persevere = false,
})

Performs a request attempt for a create route added on the server side

body The data that will be created.

route The path of the route.

params Additional data (optional).

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
      .create(route: 'product',
        body: {
           'name' : 'Video Game',
           'price' : 500,
           'discount' : 0.1
        }
      ).then((res) => print(res.success ? 'Success' : res.error!.code));

Implementation

Future<AsklessResponse> create({required String route, required dynamic body, Map<String, dynamic> ? params, bool neverTimeout = false, bool persevere = false}) async {
  assert(body!=null);
  await getIt.get<ConnectionService>().waitForConnectionOrTimeout(timeout: neverTimeout ? null : Duration(milliseconds: getIt.get<ConnectionService>().connectionConfiguration.requestTimeoutInMs));
  return getIt.get<RequestsService>().runOperationInServer(
    data: CreateCli(route: route, body: body, params: params),
    neverTimeout: neverTimeout,
    isPersevere: () => persevere,
  );
}