getResource function
Get the resource with URL resourceUrl from server.
The resource could be a text, turtle, binary file.
If resourceUrl ends with '/', i.e., a container / directory,
This function returns the bytes of a turtle string representing
the list of resources in the container / directory.
Implementation
Future<Uint8List> getResource(String resourceUrl) async {
final (:accessToken, :dPopToken) = await getTokensForResource(
resourceUrl,
'GET',
);
final response = await http.get(
Uri.parse(resourceUrl),
headers: <String, String>{
'Accept': '*/*',
'Authorization': 'DPoP $accessToken',
'Connection': 'keep-alive',
'DPoP': dPopToken,
},
);
if (response.statusCode == 200) {
return response.bodyBytes;
} else {
throw Exception('Failed to get resource $resourceUrl');
}
}