-
Notifications
You must be signed in to change notification settings - Fork 1
ProductController: POST
Für einen POST-Request übergibt man der API ID´s für Properties, Categories und ProductsAtLocations.
Beispiel für das erstellen eines Produktes (POST: /api/product):
Payload des POST-Requests:
{
"name": "DokuTest",
"price": 333,
"sku": "333",
"properties": [
{
"id": 1
}
],
"categories": [
{
"id": 1
}
],
"productsAtLocations": [
{
"locationId": 1,
"quantity": 333
}
]
}Bei erfolgreichem Request sendet der Server folgenden Response:
HTTP: 201 Created
Response Body:
{
"id": 23,
"name": "DokuTest",
"price": 333.0,
"sku": "333",
"createdAt": "2020-06-04T19:51:11.085351Z"
}Response Header:
Unter location kann die erstellte Ressource abgefragt werden.
content-length: 95
content-type: application/json; charset=utf-8
date: Sun, 31 May 2020 17:16:20 GMT
location: https://localhost:5001/api/Product/23
server: Kestrel
Bei Änderungen an Ressourcen muss immer die ganze Ressource mitgeschickt werden, nicht nur einzelne Teile.
Für alle Controller gilt: Existiert ein Objekt schon, reicht die ID. Falls das Objekt verändert werden soll, sendet man die ID + alle Properties des Objektes. Soll ein Objekt erstellt werden, lässt man die ID null.
Spezialfall OrderController: Wenn ihr zu viel Properties dem Controller sendet, werden diese ignoriert, es löst keinen Fehler aus, so kann also direkt das Objekt welches von GET kommt bearbeitet und an PUT gesendet werden !