FhirHttpRequest.fromFhirRequest constructor
FhirHttpRequest.fromFhirRequest({})
Implementation
factory FhirHttpRequest.fromFhirRequest({
required RestfulRequest type,
required String url,
Map<String, String>? headers,
Map<String, dynamic>? resource,
String? formData,
required String accept,
/// [mimeType] - specify the MimeType in the Header - this should be fhir+json
/// but there are some older systems that won't accept that
MimeType? mimeType,
/// [client] - if there's a specific client that you're going to be using
Client? client,
}) {
headers ??= <String, String>{};
headers['Accept'] = accept;
client ??= Client();
switch (type) {
case RestfulRequest.get_:
{
return FhirHttpRequest(
type: RestfulRequest.get_,
url: url,
headers: headers,
);
}
case RestfulRequest.put_:
{
headers['Content-Type'] =
mimeType == null || MimeTypeEnumMap[mimeType] == null
? 'application/fhir+json'
: MimeTypeEnumMap[mimeType]!;
return FhirHttpRequest(
type: RestfulRequest.put_,
url: url,
headers: headers,
body: resource,
);
}
case RestfulRequest.delete_:
{
return FhirHttpRequest(
type: RestfulRequest.delete_,
url: url,
headers: headers,
);
}
case RestfulRequest.patch_:
{
headers['Content-Type'] =
mimeType == null || MimeTypeEnumMap[mimeType] == null
? 'application/json-patch+json'
: MimeTypeEnumMap[mimeType]!;
return FhirHttpRequest(
type: RestfulRequest.patch_,
url: url,
headers: headers,
body: resource,
);
}
case RestfulRequest.post_:
{
headers['Content-Type'] = formData != null
? 'application/x-www-form-urlencoded'
: mimeType == null || MimeTypeEnumMap[mimeType] == null
? 'application/fhir+json'
: MimeTypeEnumMap[mimeType]!;
return FhirHttpRequest(
type: RestfulRequest.post_,
url: url,
headers: headers,
body: formData != null
? jsonDecode(formData) as Map<String, dynamic>
: resource,
);
}
}
}