post static method

Future<HttpResponse> post(
  1. String resourceUrl,
  2. dynamic data, {
  3. String? baseUrl,
  4. String? username,
  5. String? password,
  6. Database? database,
  7. Dio? dioTestClient,
})

Implementation

static Future<HttpResponse> post(String resourceUrl, dynamic data,
    {String? baseUrl,
    String? username,
    String? password,
    Database? database,
    Dio? dioTestClient}) async {
  HttpDetails httpDetails = await HttpDetails(
          baseUrl: baseUrl,
          username: username,
          password: password,
          database: database)
      .get();

  final dioClient = dioTestClient ??
      Dio(BaseOptions(
          connectTimeout: Duration(milliseconds: 100000),
          receiveTimeout: Duration(milliseconds: 100000),
          headers: {
            HttpHeaders.authorizationHeader:
                '${httpDetails.authTokenType} ${httpDetails.authToken}',
            HttpHeaders.contentTypeHeader: 'application/json'
          }));

  try {
    final Response<dynamic> response = await dioClient
        .post('${httpDetails.baseUrl}/api/$resourceUrl', data: data);

    return HttpResponse(
        statusCode: response.statusCode ?? 500, body: response.data);
  } on DioException catch (error) {
    if (error.response != null) {
      return HttpResponse(
          statusCode: error.response?.statusCode ?? 500,
          body: error.response?.data);
    } else {
      return HttpResponse(
          statusCode: error.response?.statusCode ?? 500, body: error.message);
    }
  }
}