Merge branch 'AccountsUeberarbeiten'

This commit is contained in:
2024-01-19 10:27:54 +01:00
8 changed files with 167 additions and 10 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

@@ -35,6 +35,8 @@ public class RestApiClient implements IRestAPI{
RestApiClient client1 = new RestApiClient();
client1.delete("Kind", 15);
Tagesplan t = client1.getGerichteOnTag("2023-12-17");
@@ -131,6 +133,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.
*