postConfig method
Generates an authorized POST
to the Config-API.
The path
should starts with a /
and the jsonBody
should be a valid
json. For more information see https://config.s3i.vswf.dev/apidoc/#/
.
If you need to add additional information to the header,
use additionalHeaderFields
.
Throws a FormatException if the path
could not be parsed to a
valid Uri. Throws a NetworkAuthenticationException if
AuthenticationManager.getAccessToken throws an exception. If there is no
internet connection available a SocketException
is thrown.
Implementation
Future<Response> postConfig(String path,
{Map<String, String> additionalHeaderFields = const <String, String>{},
required Map<String, dynamic> jsonBody}) async {
String originalToken = '';
try {
final AccessToken token = await authManager.getAccessToken();
originalToken = token.originalToken;
} on Exception catch (e) {
throw NetworkAuthenticationException(e);
}
final Map<String, String> headers = <String, String>{
'Content-Type': 'application/json'
}
..addAll(<String, String>{'Authorization': 'Bearer $originalToken'})
..addAll(additionalHeaderFields);
return Client().post(Uri.parse(configApiUrl + path),
headers: headers, body: utf8.encode(jsonEncode(jsonBody)));
}