2
0
mirror of https://github.com/inventree/inventree-app.git synced 2025-04-27 21:16:48 +00:00

GET request now can be provided with query parameters, and works OK

This commit is contained in:
Oliver Walters 2020-03-29 13:05:11 +11:00
parent 4da4731fb2
commit 3da5adca28

View File

@ -94,7 +94,7 @@ class InvenTreeAPI {
final data = json.decode(response.body);
// 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");
return false;
}
@ -106,7 +106,7 @@ class InvenTreeAPI {
print("Error trying connection");
print(error);
return;
return false;
});
// Here we have received a response object which is valid
@ -200,11 +200,25 @@ class InvenTreeAPI {
}
// 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 _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);
final response = await http.get(_url,