HttpApiRequest constructor

HttpApiRequest({
  1. required Uri url,
  2. required String endpoint,
  3. required Map<String, dynamic> params,
  4. RequestContext? context,
  5. Map<String, String>? headers,
  6. ApiCodec? codec,
})

Implementation

factory HttpApiRequest({
  required Uri url,
  required String endpoint,
  required Map<String, dynamic> params,
  RequestContext? context,
  Map<String, String>? headers,
  ApiCodec? codec,
}) {
  String method = 'POST';
  var words = CaseStyle.splitWords(endpoint);
  if (words.first.toLowerCase() == 'get') {
    if (words.length > 1) {
      words.removeAt(0);
    }
    method = 'GET';
  }

  return HttpApiRequest._(
    url: url.replace(
        path: url.path + '/' + words.map((w) => w.toLowerCase()).join('_')),
    method: method,
    headers: headers ?? <String, String>{},
    parameters: params,
    context: context?.finalize(),
    codec: codec,
  );
}