forked from WEB-IB-SS26/development-ib
Added Solutions for exercises 1-5
parent
d28c272ef6
commit
20691f5d4f
|
|
@ -0,0 +1,110 @@
|
||||||
|
{
|
||||||
|
"openapi": "3.0.0",
|
||||||
|
"info": {
|
||||||
|
"title": "Simple Greeting API",
|
||||||
|
"version": "1.0.0"
|
||||||
|
},
|
||||||
|
"servers": [
|
||||||
|
{
|
||||||
|
"url": "http://localhost:8080"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"paths": {
|
||||||
|
"/hello": {
|
||||||
|
"get": {
|
||||||
|
"summary": "Returns a greeting",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"name": "name",
|
||||||
|
"in":"query",
|
||||||
|
"required": true,
|
||||||
|
"description": "Name Parameter",
|
||||||
|
"schema":{
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"example": "Mr. X"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "Greeting response in plain text.",
|
||||||
|
"content": {
|
||||||
|
"text/plain": {
|
||||||
|
"schema": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"example": "Hello!"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"post": {
|
||||||
|
"summary": "Returns a plain text greeting",
|
||||||
|
"requestBody":{
|
||||||
|
"required": true,
|
||||||
|
"content": {
|
||||||
|
"text/plain":{
|
||||||
|
"schema":{
|
||||||
|
"type": "string",
|
||||||
|
"example": "YEET"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "Plain text greeting response",
|
||||||
|
"content": {
|
||||||
|
"text/plain": {
|
||||||
|
"schema": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"example": "Hello!"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"/hello-json":{
|
||||||
|
"post":{
|
||||||
|
"summary": "Ein hello/json greeting",
|
||||||
|
"requestBody":{
|
||||||
|
"required": true,
|
||||||
|
"content": {
|
||||||
|
"application/json":{
|
||||||
|
"schema":{
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"name":{
|
||||||
|
"type":"string",
|
||||||
|
"example":"Alice"
|
||||||
|
},
|
||||||
|
"age":{
|
||||||
|
"type":"integer",
|
||||||
|
"example":"23"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": ["name", "age"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "Json text greeting response",
|
||||||
|
"content": {
|
||||||
|
"text/plain": {
|
||||||
|
"schema": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"example": "Daten erhalten!"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,25 @@
|
||||||
|
## Frage 1:
|
||||||
|
Frage: Welchen Usernamen benutzt Ervin Howell?
|
||||||
|
|
||||||
|
Antwort: Antonette
|
||||||
|
## Frage 2:
|
||||||
|
Frage: Wieviele Posts wurden von dem/der Nutzer:in mit der User-ID 6 gespeichert?
|
||||||
|
|
||||||
|
Antwort: 10 Stück
|
||||||
|
## Frage 3:
|
||||||
|
Frage: Wie lautet der Titel des Posts mit der ID 1?
|
||||||
|
|
||||||
|
Antwort: "sunt aut facere repellat provident occaecati excepturi optio reprehenderit"
|
||||||
|
## Frage 4:
|
||||||
|
Frage: Wieviele Kommentare hat der Post mit der ID 1 erhalten?
|
||||||
|
|
||||||
|
Antwort: 5 Kommentare
|
||||||
|
## Frage 5:
|
||||||
|
Frage: Gibt es andere Posts (außer PostId 1), die Kommentare erhalten haben? (Ja/Nein)
|
||||||
|
|
||||||
|
Antwort: JA (insgesammt 500 Kommentare)
|
||||||
|
## Frage 6:
|
||||||
|
Frage: Wie finde ich alle Posts, die von dem/der Nutzer:in mit der User-ID 2 gespeichert wurden?
|
||||||
|
|
||||||
|
Antwort: Mit dem Befehl: "curl https://jsonplaceholder.typicode.com/posts/2/comments"
|
||||||
|
(Es sind 5 Kommentare)
|
||||||
|
|
@ -0,0 +1,14 @@
|
||||||
|
## Arbeitsschritt 1:
|
||||||
|
Arbeitsschritt: Finden Sie die ID von Professor Firenze heraus. Welchen curl-Befehl haben Sie verwendet?
|
||||||
|
|
||||||
|
Antwort: Die ID von Firenze ist "68eb4a0b-6c49-44e9-aec8-5af947d22141"
|
||||||
|
Der ensprechende Befehl ist: "curl -s https://hp-api.onrender.com/api/characters/staff"
|
||||||
|
|
||||||
|
|
||||||
|
## Arbeitsschritt 2&3:
|
||||||
|
|
||||||
|
Arbeitsschritt: Nutzen Sie diese ID, um ausschließlich die Informationen zu Professor Firenze zu finden. Welchen curl-Befehl haben Sie verwendet?
|
||||||
|
|
||||||
|
Antwort: "curl -s https://hp-api.onrender.com/api/character/68eb4a0b-6c49-44e9-aec8-5af947d22141"
|
||||||
|
Er hat die Haarfarbe blond.
|
||||||
|
|
||||||
|
|
@ -0,0 +1,126 @@
|
||||||
|
## Arbeitsschritt 1:
|
||||||
|
Arbeitsschritt iv:
|
||||||
|
Formulieren Sie einen eigenen POST-Request für:
|
||||||
|
Name: Sonnenhut
|
||||||
|
Botanischer Name: Echinacea purpurea
|
||||||
|
Standort: Sonnig
|
||||||
|
Besonderheiten: Heilpflanze, zieht Schmetterlinge an, robust
|
||||||
|
|
||||||
|
Antwort:
|
||||||
|
curl -X POST https://crudcrud.com/api/${API_ID}/staudenpflanzen \
|
||||||
|
--header 'Content-Type: application/json' \
|
||||||
|
--data '{"name": "Sonnenhut", "botanischer_name": "Echinacea purpurea", "standort": "Sonnig", "besonderheiten": "Heilpflanze, zieht Schmetterlinge an, robust"}'
|
||||||
|
|
||||||
|
|
||||||
|
Arbeitsschritt v:
|
||||||
|
Formulieren Sie einen eigenen POST-Request für:
|
||||||
|
Name: Tränendes Herz
|
||||||
|
Botanischer Name: Lamprocapnos spectabilis
|
||||||
|
Standort: Halbschatten
|
||||||
|
Besonderheiten: Herzförmige Blüten, romantisch, giftig
|
||||||
|
|
||||||
|
Antwort:
|
||||||
|
Antwort:
|
||||||
|
curl -X POST https://crudcrud.com/api/${API_ID}/staudenpflanzen \
|
||||||
|
--header 'Content-Type: application/json' \
|
||||||
|
--data '{"name": "Tränendes Herz", "botanischer_name": "Lamprocapnos spectabilis", "standort": "Halbschatten", "besonderheiten": "Herzförmige Blüten, romantisch, giftig"}'
|
||||||
|
|
||||||
|
## Arbeitsschritt 2:
|
||||||
|
|
||||||
|
Arbeitsschritt i:
|
||||||
|
curl https://crudcrud.com/api/${API_ID}/staudenpflanzen
|
||||||
|
|
||||||
|
Antwort:
|
||||||
|
[{"_id":"69e663a4ee62c203e8570037","name":"Lavendel","botanischer_name":"Lavandula angustifolia","standort":"Sonnig, trocken","besonderheiten":"Duftend, bienenfreundlich, winterhart"},{"_id":"69e663c0ee62c203e8570038","name":"Lavendel","botanischer_name":"Lavandula angustifolia","standort":"Sonnig, trocken","besonderheiten":"Duftend, bienenfreundlich, winterhart"},{"_id":"69e66501ee62c203e8570039","name":"Tränendes Herz","botanischer_name":"Lamprocapnos spectabilis","standort":"Halbschatten","besonderheiten":"Herzförmige Blüten, romantisch, giftig"},{"_id":"69e6651cee62c203e857003a","name":"Sonnenhut","botanischer_name":"Echinacea purpurea","standort":"Sonnig","besonderheiten":"Heilpflanze, zieht Schmetterlinge an, robust"}]
|
||||||
|
|
||||||
|
|
||||||
|
Arbeitsschritt ii:
|
||||||
|
Finden Sie die IDs der Funkie, des Sonnenhuts und der Pfingstrose heraus und notieren Sie sich diese.
|
||||||
|
|
||||||
|
Antwort:
|
||||||
|
Funkie: "69e666dbee62c203e857003c"
|
||||||
|
Sonnenhut: "69e6651cee62c203e857003a"
|
||||||
|
Pfingstrose: "69e666e9ee62c203e857003d"
|
||||||
|
|
||||||
|
## Arbeitsschritt 3:
|
||||||
|
|
||||||
|
Arbeitsschritt i:
|
||||||
|
curl -X PUT https://crudcrud.com/api/${API_ID}/staudenpflanzen/<id> \
|
||||||
|
--header 'Content-Type: application/json' \
|
||||||
|
--data '{"name": "Sonnenhut", "botanischer_name": "Echinacea purpurea", "standort": "Sonnig", "besonderheiten": "Heilpflanze, zieht Schmetterlinge, schneckenanfällig"}'
|
||||||
|
|
||||||
|
Antwort:
|
||||||
|
curl -X PUT https://crudcrud.com/api/${API_ID}/staudenpflanzen/69e6651cee62c203e857003a \
|
||||||
|
--header 'Content-Type: application/json' \
|
||||||
|
--data '{"name": "Sonnenhut", "botanischer_name": "Echinacea purpurea", "standort": "Sonnig", "besonderheiten": "Heilpflanze, zieht Schmetterlinge, schneckenanfällig"}'
|
||||||
|
|
||||||
|
Antwort des Servers mit "curl https://crudcrud.com/api/${API_ID}/staudenpflanzen":
|
||||||
|
...
|
||||||
|
{"_id":"69e6651cee62c203e857003a","name":"Sonnenhut","botanischer_name":"Echinacea purpurea","standort":"Sonnig","besonderheiten":"Heilpflanze, zieht Schmetterlinge, schneckenanfällig"}
|
||||||
|
...
|
||||||
|
|
||||||
|
|
||||||
|
Arbeitsschritt ii:
|
||||||
|
Formulieren Sie einen eigenen PUT-Request für die Funkie und ändern Sie die Besonderheiten zu "Dekoratives Laub, schneckenanfällig, robust".
|
||||||
|
|
||||||
|
Antwort:
|
||||||
|
curl -X PUT https://crudcrud.com/api/${API_ID}/staudenpflanzen/69e666dbee62c203e857003c \
|
||||||
|
--header 'Content-Type: application/json' \
|
||||||
|
--data '{"name":"Funkie","botanischer_name":"Hosta","standort":"Halbschatten bis Schatten","besonderheiten":"Dekoratives Laub, schneckenanfällig, robust"}'
|
||||||
|
|
||||||
|
Antwort des Servers mit "curl https://crudcrud.com/api/${API_ID}/staudenpflanzen":
|
||||||
|
...
|
||||||
|
{"_id":"69e666dbee62c203e857003c","name":"Funkie","botanischer_name":"Hosta","standort":"Halbschatten bis Schatten","besonderheiten":"Dekoratives Laub, schneckenanfällig, robust"}
|
||||||
|
...
|
||||||
|
|
||||||
|
## Arbeitsschritt 4:
|
||||||
|
|
||||||
|
Arbeitsschritt i:
|
||||||
|
curl -X DELETE https://crudcrud.com/api/${API_ID}/staudenpflanzen/69e666e9ee62c203e857003d
|
||||||
|
|
||||||
|
|
||||||
|
## Arbeitsschritt 5:
|
||||||
|
|
||||||
|
Arbeitsschritt:
|
||||||
|
curl https://crudcrud.com/api/${API_ID}/staudenpflanzen | jq
|
||||||
|
|
||||||
|
Antwort:
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"_id":"69e663a4ee62c203e8570037",
|
||||||
|
"name":"Lavendel",
|
||||||
|
"botanischer_name":"Lavandula angustifolia",
|
||||||
|
"standort":"Sonnig, trocken",
|
||||||
|
"besonderheiten":"Duftend, bienenfreundlich, winterhart"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"_id":"69e663c0ee62c203e8570038",
|
||||||
|
"name":"Lavendel",
|
||||||
|
"botanischer_name":"Lavandula angustifolia",
|
||||||
|
"standort":"Sonnig, trocken",
|
||||||
|
"besonderheiten":"Duftend, bienenfreundlich, winterhart"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"_id":"69e66501ee62c203e8570039",
|
||||||
|
"name":"Tränendes Herz",
|
||||||
|
"botanischer_name":"Lamprocapnos spectabilis",
|
||||||
|
"standort":"Halbschatten",
|
||||||
|
"besonderheiten":"Herzförmige Blüten, romantisch, giftig"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"_id":"69e6651cee62c203e857003a",
|
||||||
|
"name":"Sonnenhut",
|
||||||
|
"botanischer_name":"Echinacea purpurea",
|
||||||
|
"standort":"Sonnig",
|
||||||
|
"besonderheiten":"Heilpflanze, zieht Schmetterlinge, schneckenanfällig"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"_id":"69e666dbee62c203e857003c",
|
||||||
|
"name":"Funkie",
|
||||||
|
"botanischer_name":"Hosta",
|
||||||
|
"standort":"Halbschatten bis Schatten",
|
||||||
|
"besonderheiten":"Dekoratives Laub, schneckenanfällig, robust"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -0,0 +1,102 @@
|
||||||
|
## Arbeitsschritt 1:
|
||||||
|
Arbeitsschritt:
|
||||||
|
Erstelle ein JSON-Objekt mit Informationen über eine Person:
|
||||||
|
Name: Alex
|
||||||
|
Alter: 30
|
||||||
|
Wohnort: Berlin
|
||||||
|
|
||||||
|
Antwort:
|
||||||
|
{
|
||||||
|
"person": {
|
||||||
|
"name": "Alex",
|
||||||
|
"alter": "30",
|
||||||
|
"wohnort": "Berlin"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
## Arbeitsschritt 2:
|
||||||
|
|
||||||
|
Arbeitsschritt:
|
||||||
|
Erstelle ein JSON-Objekt zu einem Produkt:
|
||||||
|
Produktname: Kopfhörer
|
||||||
|
Preis: 89.99
|
||||||
|
Verfügbarkeit: Ja
|
||||||
|
Farben: Schwarz und Weiß (als Liste)
|
||||||
|
|
||||||
|
Antwort:
|
||||||
|
{
|
||||||
|
"produkt":{
|
||||||
|
"produktname": "Kopfhöhrer",
|
||||||
|
"preis": "89.99",
|
||||||
|
"verfügbarkeit": "ja",
|
||||||
|
"farben":[
|
||||||
|
"schwarz",
|
||||||
|
"weiss"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
## Arbeitsschritt 3:
|
||||||
|
|
||||||
|
Arbeitsschritt:
|
||||||
|
Erstelle ein JSON-Objekt zu einem Benutzer inklusive Adresse:
|
||||||
|
Benutzername: maria1999
|
||||||
|
Passwort: abc123
|
||||||
|
Rolle: Admin
|
||||||
|
Adresse: Bauernring 15 (Straße), Weilbach (Stadt) und 12345 (Postleitzahl) (als verschachteltes Objekt)
|
||||||
|
|
||||||
|
Antwort:
|
||||||
|
{
|
||||||
|
"benutzer":{
|
||||||
|
"benutzername":"maria1999",
|
||||||
|
"passwort":"abc123",
|
||||||
|
"rolle":"admin",
|
||||||
|
"addresse":{
|
||||||
|
"straße": "Bauernring 15",
|
||||||
|
"stadt": "Weilbach",
|
||||||
|
"postleitzahl": "12345"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
## Arbeitsschritt 4:
|
||||||
|
|
||||||
|
Arbeitsschritt:
|
||||||
|
Erstelle ein Array mit zwei Aufgabenobjekten. Jede Aufgabe hat einen Titel und einen erledigt-Status (true/false)
|
||||||
|
|
||||||
|
Antwort:
|
||||||
|
{
|
||||||
|
"aufgaben": [
|
||||||
|
"aufgabe":{
|
||||||
|
"titel": "JSON Lernen",
|
||||||
|
"erledigt":"true"
|
||||||
|
},
|
||||||
|
"aufgabe":{
|
||||||
|
"titel": "SWAGGER Lernen",
|
||||||
|
"erledigt":"false"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
## Arbeitsschritt 5:
|
||||||
|
|
||||||
|
Arbeitsschritt:
|
||||||
|
Erstelle ein JSON-Objekt für einen Blogeintrag mit folgendem Aufbau:
|
||||||
|
Titel, Autor, Inhalt des Beitrags
|
||||||
|
Ein Kommentar als verschachteltes Objekt mit Autor und Text
|
||||||
|
|
||||||
|
Antwort:
|
||||||
|
{
|
||||||
|
"blogeintrag":{
|
||||||
|
"titel": "Ein Test Titel",
|
||||||
|
"autor": "Mr X.",
|
||||||
|
"inhalt": "Lorem ipsum ...",
|
||||||
|
"kommentar": {
|
||||||
|
"autor": "Kommentator von dem Blogeintrag",
|
||||||
|
"text": "Lorem ipsum..."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue