Search code examples
rest.net-corejson-api

JSON API .Net Core Put and Patch Examples


I am testing boilerplate library for dotnet core with json:api specification from github repo {json:api}. The endpoints for GET (with or without query), POST & DELETE are working as expected when I send from postman. But I couldn't find working examples to change the existing resource with PUT or PATCH. When i send patch request with data, it give me back response "200 OK" but it didn't change in database. Below are my request and response.

  Request GET : http://localhost:5000/api/people -> 200 OK
  Response : [
  {
    "name": "Samuel",
    "articles": null,
    "id": 2,
    "stringId": "2"
  },
  {
    "name": "John",
    "articles": null,
    "id": 3,
    "stringId": "3"
  },
  {
    "name": "Robbin",
    "articles": null,
    "id": 4,
    "stringId": "4"
   } ]

  Request GET: http://localhost:5000/api/people/2 -> 200 OK
  Response : {
   "name": "Samuel",
   "articles": null,
   "id": 2,
   "stringId": "2" 
  }

  Request GET: http://localhost:5000/api/people/2?include=articles -> 200 OK
  Response : {
   "name": "Samuel",
   "articles": [],
   "id": 2,
   "stringId": "2" 
  }

  Request POST: http://localhost:5000/api/people -> 201 Created
  Request Body: {"name":"Samuel"}
  Response : {
   "name": "Samuel",
   "articles": null,
   "id": 2,
   "stringId": "2" 
  }

  Request DELETE: http://localhost:5000/api/people/2 -> 204 No Content

How can I update data?


Solution

  • I made a final decision after reading specification documents of JSONAPI and OData. I will just stick to my own format for better understanding of my own code and I recommend Swagger for Api Documentation. It doesn't make sense if the spec doesn't meet my requirement even when people are telling it's the standard.