mirror of
https://gitlab.com/nkming2/nc-photos.git
synced 2025-02-02 14:56:20 +01:00
API request with query params
This commit is contained in:
parent
1746758d93
commit
f66018d36b
1 changed files with 8 additions and 4 deletions
|
@ -43,11 +43,12 @@ class Api {
|
|||
String method,
|
||||
String endpoint, {
|
||||
Map<String, String>? header,
|
||||
Map<String, String>? queryParameters,
|
||||
String? body,
|
||||
Uint8List? bodyBytes,
|
||||
bool isResponseString = true,
|
||||
}) async {
|
||||
final url = _makeUri(endpoint);
|
||||
final url = _makeUri(endpoint, queryParameters: queryParameters);
|
||||
final req = http.Request(method, url)
|
||||
..headers.addAll({
|
||||
"authorization": getAuthorizationHeaderValue(_account),
|
||||
|
@ -87,16 +88,19 @@ class Api {
|
|||
isResponseString ? response.body : response.bodyBytes);
|
||||
}
|
||||
|
||||
Uri _makeUri(String endpoint) {
|
||||
Uri _makeUri(
|
||||
String endpoint, {
|
||||
Map<String, String>? queryParameters,
|
||||
}) {
|
||||
final splits = _account.address.split("/");
|
||||
final authority = splits[0];
|
||||
final path = splits.length > 1
|
||||
? splits.sublist(1).join("/") + "/$endpoint"
|
||||
: endpoint;
|
||||
if (_account.scheme == "http") {
|
||||
return Uri.http(authority, path);
|
||||
return Uri.http(authority, path, queryParameters);
|
||||
} else {
|
||||
return Uri.https(authority, path);
|
||||
return Uri.https(authority, path, queryParameters);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue