mirror of
https://github.com/inventree/inventree-app.git
synced 2025-04-28 05:26:47 +00:00
GET request now can be provided with query parameters, and works OK
This commit is contained in:
parent
4da4731fb2
commit
3da5adca28
20
lib/api.dart
20
lib/api.dart
@ -94,7 +94,7 @@ class InvenTreeAPI {
|
|||||||
final data = json.decode(response.body);
|
final data = json.decode(response.body);
|
||||||
|
|
||||||
// We expect certain response from the server
|
// We expect certain response from the server
|
||||||
if (!data.containsKey("sedrver") || !data.containsKey("version")) {
|
if (!data.containsKey("server") || !data.containsKey("version")) {
|
||||||
print("Incorrect keys in server response");
|
print("Incorrect keys in server response");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -106,7 +106,7 @@ class InvenTreeAPI {
|
|||||||
print("Error trying connection");
|
print("Error trying connection");
|
||||||
print(error);
|
print(error);
|
||||||
|
|
||||||
return;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
// Here we have received a response object which is valid
|
// Here we have received a response object which is valid
|
||||||
@ -200,11 +200,25 @@ class InvenTreeAPI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Perform a GET request
|
// Perform a GET request
|
||||||
Future<http.Response> get(String url) async {
|
Future<http.Response> get(String url, {Map<String, String> params}) async {
|
||||||
|
|
||||||
var _url = _makeUrl(url);
|
var _url = _makeUrl(url);
|
||||||
var _headers = _defaultHeaders();
|
var _headers = _defaultHeaders();
|
||||||
|
|
||||||
|
// If query parameters are supplied, form a query string
|
||||||
|
if (params != null && params.isNotEmpty) {
|
||||||
|
String query = '?';
|
||||||
|
|
||||||
|
params.forEach((K, V) => query += K + '=' + V + '&');
|
||||||
|
|
||||||
|
_url += query;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove extraneous character if present
|
||||||
|
if (_url.endsWith('&')) {
|
||||||
|
_url = _url.substring(0, _url.length - 1);
|
||||||
|
}
|
||||||
|
|
||||||
print("GET: " + _url);
|
print("GET: " + _url);
|
||||||
|
|
||||||
final response = await http.get(_url,
|
final response = await http.get(_url,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user