mirror of
https://gitlab.com/nkming2/nc-photos.git
synced 2025-02-02 23:06:21 +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 method,
|
||||||
String endpoint, {
|
String endpoint, {
|
||||||
Map<String, String>? header,
|
Map<String, String>? header,
|
||||||
|
Map<String, String>? queryParameters,
|
||||||
String? body,
|
String? body,
|
||||||
Uint8List? bodyBytes,
|
Uint8List? bodyBytes,
|
||||||
bool isResponseString = true,
|
bool isResponseString = true,
|
||||||
}) async {
|
}) async {
|
||||||
final url = _makeUri(endpoint);
|
final url = _makeUri(endpoint, queryParameters: queryParameters);
|
||||||
final req = http.Request(method, url)
|
final req = http.Request(method, url)
|
||||||
..headers.addAll({
|
..headers.addAll({
|
||||||
"authorization": getAuthorizationHeaderValue(_account),
|
"authorization": getAuthorizationHeaderValue(_account),
|
||||||
|
@ -87,16 +88,19 @@ class Api {
|
||||||
isResponseString ? response.body : response.bodyBytes);
|
isResponseString ? response.body : response.bodyBytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
Uri _makeUri(String endpoint) {
|
Uri _makeUri(
|
||||||
|
String endpoint, {
|
||||||
|
Map<String, String>? queryParameters,
|
||||||
|
}) {
|
||||||
final splits = _account.address.split("/");
|
final splits = _account.address.split("/");
|
||||||
final authority = splits[0];
|
final authority = splits[0];
|
||||||
final path = splits.length > 1
|
final path = splits.length > 1
|
||||||
? splits.sublist(1).join("/") + "/$endpoint"
|
? splits.sublist(1).join("/") + "/$endpoint"
|
||||||
: endpoint;
|
: endpoint;
|
||||||
if (_account.scheme == "http") {
|
if (_account.scheme == "http") {
|
||||||
return Uri.http(authority, path);
|
return Uri.http(authority, path, queryParameters);
|
||||||
} else {
|
} else {
|
||||||
return Uri.https(authority, path);
|
return Uri.https(authority, path, queryParameters);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue