getOne method
Returns single item by its id.
Throws 404 ClientException
in case an empty id
is provided.
Implementation
Future<M> getOne(
String id, {
String? expand,
String? fields,
Map<String, dynamic> query = const {},
Map<String, String> headers = const {},
}) async {
if (id.isEmpty) {
throw ClientException(
url: client.buildUrl("$baseCrudPath/"),
statusCode: 404,
response: <String, dynamic>{
"code": 404,
"message": "Missing required record id.",
"data": <String, dynamic>{},
},
);
}
final enrichedQuery = Map<String, dynamic>.of(query);
enrichedQuery["expand"] ??= expand;
enrichedQuery["fields"] ??= fields;
return client
.send(
"$baseCrudPath/${Uri.encodeComponent(id)}",
query: enrichedQuery,
headers: headers,
)
.then((data) => itemFactoryFunc(data as Map<String, dynamic>? ?? {}));
}