BloomResponse.methodNotAllowed constructor

BloomResponse.methodNotAllowed([
  1. String message = 'Method Not Allowed',
  2. Map<String, String>? headers
])

Helper factory constructor for HTTP 405 Method Not Allowed JSON error responses.

Example

return BloomResponse.methodNotAllowed('Method Not Allowed', headers: {'allow': 'GET, POST'});

Implementation

factory BloomResponse.methodNotAllowed([
  String message = 'Method Not Allowed',
  Map<String, String>? headers,
]) {
  final finalHeaders = <String, String>{
    'content-type': 'application/json; charset=utf-8',
    'Content-Type': 'application/json; charset=utf-8',
    ...?headers,
  };
  return BloomResponse(
    statusCode: 405,
    headers: finalHeaders,
    body: Uint8List.fromList(
        utf8.encode(jsonEncode({'error': message, 'statusCode': 405}))),
  );
}