Request constructor

Request(
  1. String method,
  2. List<String> pathSegments, {
  3. Map<String, dynamic>? bodyMap,
  4. String? bodyText,
  5. Map<String, String>? params,
})

Creates a new Request object.

If bodyMap is specified, the content will be encoded as JSON, alongside with the appropriate header.

Implementation

factory Request(
  String method,
  List<String> pathSegments, {
  Map<String, dynamic>? bodyMap,
  String? bodyText,
  Map<String, String>? params,
}) {
  if (bodyMap != null && bodyText != null) {
    throw ArgumentError(
        'Only one of "bodyMap" or "bodyText" must be specified.');
  }
  bodyText ??= bodyMap == null ? null : convert.json.encode(bodyMap);
  final headers =
      bodyText == null ? null : {'Content-Type': 'application/json'};
  return Request._(method, pathSegments, bodyText, headers, params);
}