post<T> static method

Future<T> post<T>(
  1. String endpoint, {
  2. Map<String, dynamic>? params,
  3. Map<String, String>? headers,
  4. Object? body,
  5. Function? callback,
})

Sends a POST request.

Implementation

static Future<T> post<T>(
  String endpoint, {
  Map<String, dynamic>? params,
  Map<String, String>? headers,
  Object? body,
  Function? callback,
}) async {
  ServerRequest request = ServerRequest(
    method: 'POST',
    endpoint: endpoint,
    params: params,
    body: body,
    url: url!,
  );

  Response response;

  try {
    response = await request.send();
  } catch (error) {
    return Future.error(error);
  }

  if (callback != null) {
    return callback(jsonDecode(response.body));
  }

  if (T == ServerResponse) {
    return ServerResponse(response) as T;
  }

  return response as T;
}