Sambhav jain
Sambhav jain

Reputation: 27

updating data in json server

i want to update only name in my json server but when i updateName() all details of object is removed except id and updated name

 updateName(id: string, name: string): Observable<any> {
    const shipmentUrl = `${this.url}/${id}`;
    return this.http.put<any>(shipmentUrl, {
      name: name,
    });

object before updateName

{
    "id": "S1000",
    "name": "T-shirts(Summer2018) from Shanghai to Hamburg",
    "cargo": [
      {
        "type": "Fabric",
        "description": "1000 Blue T-shirts",
        "volume": "2"
      },
      {
        "type": "Fabric",
        "description": "2000 Green T-shirts",
        "volume": "3"
      }
    ],
    "mode": "sea",
    "type": "FCL",
    "destination": "Saarbrücker Str. 38, 10405 Berlin",
    "origin": "Shanghai Port",
    "services": [
      {
        "type": "customs"
      }
    ],
    "total": "1000",
    "status": "ACTIVE",
    "userId": "U1000"
  },

object after updateName

{ "name": "shoes", "id": "S1000" },

Upvotes: 0

Views: 3652

Answers (1)

akkonrad
akkonrad

Reputation: 1073

if your json server is a rest server and you want to change one property only, then you should try PATCH request, not PUT. PUT updates the entire object, PATCH is changing only mentioned fields.

Upvotes: 2

Related Questions