defaultBinding function
Return a default binding given method and contentType.
method - The HTTP method of the request (e.g., GET, POST).
contentType - The MIME type of the request body.
Returns the appropriate binding based on the method and content type.
Implementation
Binding defaultBinding(String method, String contentType) {
// If the method is GET, use the QueryBinding.
if (method.toUpperCase() == 'GET') {
return QueryBinding();
}
// Determine the MIME type from the content type.
final mime =
MimeType.values.where((m) => m.value == contentType).firstOrNull ?? "";
// Return the appropriate binding based on the MIME type.
switch (mime) {
case MimeType.json:
return jsonBinding;
case MimeType.xml:
case MimeType.xml2:
throw UnimplementedError('XML binding not yet supported.');
case MimeType.multipartPostForm:
return multipartBinding;
case MimeType.postForm:
return formBinding;
default:
return formBinding;
}
}