Account laden

This commit is contained in:
2024-01-18 13:01:01 +01:00
parent 1db44e7b22
commit 39b9266067
4 changed files with 87 additions and 1 deletions

View File

@@ -17,6 +17,8 @@ public interface IRestAPI {
String get (String controllerName, int id, boolean bezahlt);
String get(String controllerName, String[] params);
//endregion
// region put

View File

@@ -125,6 +125,36 @@ public class RestApiClient implements IRestAPI{
}
}
@Override
public String get(String controllerName, String[] params) {
String ende = "";
for (String str : params) {
ende += str + ",";
}
ende = ende.substring(0, ende.length() - 1);
URI apiUri = URI.create(String.format("%s/%s?%s", urlBase, controllerName, ende));
HttpRequest httpRequest = HttpRequest.newBuilder()
.uri(apiUri)
.GET()
.build();
try {
// Send the request and get the response
HttpResponse<String> httpResponse = client.send(httpRequest, HttpResponse.BodyHandlers.ofString());
// Print the response status code and body
System.out.println("Status Code: " + httpResponse.statusCode() + httpResponse.body());
return httpResponse.body();
//System.out.println("Response Body: " + test);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
/**
* Methode für einen Put-Aufruf. Aktualisiert einen Eintrag.
*