JSON API .Net Core Put and Patch Examples



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















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?










share|improve this question






























    0















    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?










    share|improve this question


























      0












      0








      0








      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?










      share|improve this question
















      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?







      rest .net-core json-api






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 15 '18 at 10:46







      phonemyatt

















      asked Nov 15 '18 at 10:09









      phonemyattphonemyatt

      475216




      475216






















          2 Answers
          2






          active

          oldest

          votes


















          1














          I found in documents that require to includes following two headers for different api calls and body request is also different for PATCH.




          "Accept: application/vnd.api+json" <--- This needs to put in header
          "Content-Type: application/vnd.api+json" <--- This also needed.

          Request PATCH: http://localhost:5000/api/people/3 -> 200 OK
          // Request body becomes text, anybody knows how to format to JSON?
          Request Body(Text):
          "data":
          "type": "people",
          "attributes":
          "name": "John"




          Response :
          "data":
          "attributes":
          "name": "John"
          ,
          "relationships":
          "articles":
          "links":
          "self":
          "http://localhost:5000/api/people/3/relationships/articles",
          "related": "http://localhost:5000/api/people/3/articles"


          ,
          "type": "people",
          "id": "3"







          share|improve this answer






























            1














            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.






            share|improve this answer

























              Your Answer






              StackExchange.ifUsing("editor", function ()
              StackExchange.using("externalEditor", function ()
              StackExchange.using("snippets", function ()
              StackExchange.snippets.init();
              );
              );
              , "code-snippets");

              StackExchange.ready(function()
              var channelOptions =
              tags: "".split(" "),
              id: "1"
              ;
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function()
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled)
              StackExchange.using("snippets", function()
              createEditor();
              );

              else
              createEditor();

              );

              function createEditor()
              StackExchange.prepareEditor(
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader:
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              ,
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              );



              );













              draft saved

              draft discarded


















              StackExchange.ready(
              function ()
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53316991%2fjson-api-net-core-put-and-patch-examples%23new-answer', 'question_page');

              );

              Post as a guest















              Required, but never shown

























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              1














              I found in documents that require to includes following two headers for different api calls and body request is also different for PATCH.




              "Accept: application/vnd.api+json" <--- This needs to put in header
              "Content-Type: application/vnd.api+json" <--- This also needed.

              Request PATCH: http://localhost:5000/api/people/3 -> 200 OK
              // Request body becomes text, anybody knows how to format to JSON?
              Request Body(Text):
              "data":
              "type": "people",
              "attributes":
              "name": "John"




              Response :
              "data":
              "attributes":
              "name": "John"
              ,
              "relationships":
              "articles":
              "links":
              "self":
              "http://localhost:5000/api/people/3/relationships/articles",
              "related": "http://localhost:5000/api/people/3/articles"


              ,
              "type": "people",
              "id": "3"







              share|improve this answer



























                1














                I found in documents that require to includes following two headers for different api calls and body request is also different for PATCH.




                "Accept: application/vnd.api+json" <--- This needs to put in header
                "Content-Type: application/vnd.api+json" <--- This also needed.

                Request PATCH: http://localhost:5000/api/people/3 -> 200 OK
                // Request body becomes text, anybody knows how to format to JSON?
                Request Body(Text):
                "data":
                "type": "people",
                "attributes":
                "name": "John"




                Response :
                "data":
                "attributes":
                "name": "John"
                ,
                "relationships":
                "articles":
                "links":
                "self":
                "http://localhost:5000/api/people/3/relationships/articles",
                "related": "http://localhost:5000/api/people/3/articles"


                ,
                "type": "people",
                "id": "3"







                share|improve this answer

























                  1












                  1








                  1







                  I found in documents that require to includes following two headers for different api calls and body request is also different for PATCH.




                  "Accept: application/vnd.api+json" <--- This needs to put in header
                  "Content-Type: application/vnd.api+json" <--- This also needed.

                  Request PATCH: http://localhost:5000/api/people/3 -> 200 OK
                  // Request body becomes text, anybody knows how to format to JSON?
                  Request Body(Text):
                  "data":
                  "type": "people",
                  "attributes":
                  "name": "John"




                  Response :
                  "data":
                  "attributes":
                  "name": "John"
                  ,
                  "relationships":
                  "articles":
                  "links":
                  "self":
                  "http://localhost:5000/api/people/3/relationships/articles",
                  "related": "http://localhost:5000/api/people/3/articles"


                  ,
                  "type": "people",
                  "id": "3"







                  share|improve this answer













                  I found in documents that require to includes following two headers for different api calls and body request is also different for PATCH.




                  "Accept: application/vnd.api+json" <--- This needs to put in header
                  "Content-Type: application/vnd.api+json" <--- This also needed.

                  Request PATCH: http://localhost:5000/api/people/3 -> 200 OK
                  // Request body becomes text, anybody knows how to format to JSON?
                  Request Body(Text):
                  "data":
                  "type": "people",
                  "attributes":
                  "name": "John"




                  Response :
                  "data":
                  "attributes":
                  "name": "John"
                  ,
                  "relationships":
                  "articles":
                  "links":
                  "self":
                  "http://localhost:5000/api/people/3/relationships/articles",
                  "related": "http://localhost:5000/api/people/3/articles"


                  ,
                  "type": "people",
                  "id": "3"








                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 15 '18 at 11:05









                  phonemyattphonemyatt

                  475216




                  475216























                      1














                      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.






                      share|improve this answer





























                        1














                        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.






                        share|improve this answer



























                          1












                          1








                          1







                          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.






                          share|improve this answer















                          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.







                          share|improve this answer














                          share|improve this answer



                          share|improve this answer








                          edited Jan 23 at 14:59

























                          answered Nov 16 '18 at 11:16









                          phonemyattphonemyatt

                          475216




                          475216



























                              draft saved

                              draft discarded
















































                              Thanks for contributing an answer to Stack Overflow!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid


                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.

                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function ()
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53316991%2fjson-api-net-core-put-and-patch-examples%23new-answer', 'question_page');

                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              Use pre created SQLite database for Android project in kotlin

                              Darth Vader #20

                              Ondo