Showing posts with label JSON. Show all posts
Showing posts with label JSON. Show all posts

2020-11-20

2020-11-20 Friday - REST API Design Guidance (PUT, POST, or PATCH for update?)

Photo by Ryan Quintal on Unsplash


I spent some time this evening assembling a response to a Stackoverflow question:

My answer: 

(Note:2025-04-06 Sunday: Addendum, at bottom)

Reading the RFCs is highly recommended

RFC 7231 Hypertext Transfer Protocol (HTTP/1.1): Semantics and Content

https://tools.ietf.org/html/rfc7231

In particular, pay close attention to Section 4.3 Method Definitions

https://tools.ietf.org/html/rfc7231#section-4.3

    • "The POST method requests that the target resource process the representation enclosed in the request according to the resource's own specific semantics."
    • "The PUT method requests that the state of the target resource be created or replaced with the state defined by the representation enclosed in the request message payload."

Which is to say - that you will find variation in how an update action is processed (some folks use POST, some use PATCH, many use PUT), depending on their implementation-specific resource semantics.

In your example, it appears that the PUT resource-specific semantic implementation is treating the submitted data element as a full replacement - and since you did not include the age element - it is left as null.

PATCH is indeed intended as the verb for doing a partial update, refer to:

RFC 5789 PATCH Method for HTTP

https://tools.ietf.org/html/rfc5789

    • "The PATCH method requests that a set of changes described in the request entity be applied to the resource identified by the Request-URI. The set of changes is represented in a format called a "patch document" identified by a media type."
    • "The difference between the PUT and PATCH requests is reflected in the way the server processes the enclosed entity to modify the resource identified by the Request-URI. In a PUT request, the enclosed entity is considered to be a modified version of the resource stored on the origin server, and the client is requesting that the stored version be replaced. With PATCH, however, the enclosed entity contains a set of instructions describing how a resource currently residing on the origin server should be modified to produce a new version. The PATCH method affects the resource identified by the Request-URI, and it also MAY have side effects on other resources; i.e., new resources may be created, or existing ones modified, by the application of a PATCH."
    • "PATCH is neither safe nor idempotent"
    • "There is no guarantee that a resource can be modified with PATCH. Further, it is expected that different patch document formats will be appropriate for different types of resources and that no single format will be appropriate for all types of resources. Therefore, there is no single default patch document format that implementations are required to support."
    • "Clients need to choose when to use PATCH rather than PUT. For example, if the patch document size is larger than the size of the new resource data that would be used in a PUT, then it might make sense to use PUT instead of PATCH. A comparison to POST is even more difficult, because POST is used in widely varying ways and can encompass PUT and PATCH-like operations if the server chooses. If the operation does not modify the resource identified by the Request-URI in a predictable way, POST should be considered instead of PATCH or PUT."

When using PATCH for JSON type documents, see

RFC 6909 - JavaScript Object Notation (JSON) Patch

https://tools.ietf.org/html/rfc6902

    • "JSON Patch defines a JSON document structure for expressing a sequence of operations to apply to a JavaScript Object Notation (JSON) document; it is suitable for use with the HTTP PATCH method. The "application/json-patch+json" media type is used to identify such patch documents."

Additionally, you may find these resources useful

  1. https://restfulapi.net/http-methods/
  2. https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods
  3. https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/PATCH
  4. https://en.wikipedia.org/wiki/Patch_verb
  5. http://jsonpatch.com/
  6. https://microservices.io/book

 

Interesting API Update Examples 

Okta

 

2025-04-06 Sunday: Addendums

https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Resources_and_specifications

RFC 9110: HTTP Semantics
See: section 9.3.3
https://www.rfc-editor.org/rfc/rfc9110.html#POST

  • "The POST method requests that the target resource process the representation enclosed in the request according to the resource's own specific semantics"
  • "An origin server indicates response semantics by choosing an appropriate status code depending on the result of processing the POST request"


Also see:
RFC 9113: HTTP/2
https://www.rfc-editor.org/rfc/rfc9113

RFC 9114: HTTP/3
https://www.rfc-editor.org/rfc/rfc9114

 

2019-04-20

2019-04-20 Saturday - Eclipse IDE v4.11 Release 2019-03 JSON Schema Validation Issues

During some recent testing of the latest release of the Eclipse IDE, v4.11, Release 2019-03 - I discovered some issues with JSON Schema Validation:

First:

While looking for a better JSON editor - I installed this plugin:

But, I observed that
  • It appears that when this plugin is installed - JSON Schema Validation (i.e. after registering the file pattern and schema URL via Window > Preferences > JSON > JSON Catalog) no longer works.
  • I repeated this test several times, by uninstalling the plugin - confirming that Schema Validation worked - and then re-installing the plugin and confirming that Schema Validation no longer worked.
  • I did not see any errors being logged to the Eclipse log file.
  • Tested with Java JDK 12, on a Windows 10 laptop
 Issue #26 Submitted

Second:

While experimenting with the JSON Schema Validation capabilities of the latest Eclipse release (v4.11, 2019-03) - I noted an error in the log (see my stackoverflow submission) - even though validation appeared to be working.

  • relequestual replied soon after: "JSON Schema core dev here. Yeah this looks fine in terms of JSON Schema. No idea why an error is being throw" 
 Issue #546541 Submitted:

Subsequently:

  • It appears that the exception is no longer thrown. 


  • ....a different error messages shows in the log - with a different exception is thrown. 

References:


Observation: 

There are quite a few open bugs within the Eclipse WTP Source Editing and wst.json component - that have not been addressed in years...

2016-04-22

2016-04-22 Friday - Jo: a shell command to create JSON

A very nice (and elegant) command line utility (Jo, a shell command to create JSON) by Jan-Piet Mens (@jpmens)
http://jpmens.net/2016/03/05/a-shell-command-to-create-json-jo/

2015-04-02

2015-04-02 Thursday - PostgreSQL 9.4 JSON Support

I'm experimenting with the JSON support features in PostgreSQL 9.4 - this post is a placeholder for interesting things I want to remember.

PostgreSQL JSON related blog posts by others:

PostgreSQL documentation links:

2011-12-01

2011-12-01 Thursday - Bayeux Protocol


I'm exploring some potential design ideas leveraging server-side JavaScript, and so have started compiling a list of articles and resources to review::

http://nodejs.org/


Standard ECMA-262ECMAScript Language SpecificationEdition 5.1 (June 2011)
http://www.ecma-international.org/publications/standards/Ecma-262.htm


Bayeux Protocol -- Bayeux 1.0.0
http://svn.cometd.org/trunk/bayeux/bayeux.html

Introduction to Bayeux Protocol (HTTP Publish-Subscribe) 
http://blogs.oracle.com/slc/entry/introduction_to_bayeux_protoco

Cometd is a scalable HTTP-based event routing bus that uses a push technology pattern known as Comet. 
http://cometd.org/
http://cometd.org/documentation

http://code.google.com/p/cometd/
http://code.google.com/p/cometd/wiki/BayeuxCometdDocumentation
CometD.NET is a C# client library for the Bayeux protocol
https://github.com/Oyatel/CometD.NET


http://cometdaily.com/

V8 JavaScript Engine
http://code.google.com/p/v8/

2011-05-09

2011-05-09 Monday - Why You Might Need JSON

"Even the most humble carpenter has hammers of different sizes"


Hypothetical Problem:  
An average payload of 50-100 bytes of data needs to be made available via an online service - but an enterprise canonical XSD structure might flood the network with about 200K of just empty tag elements alone.

Proposed Solution:

For certain types of data servcies, a light-weight RESTful service using JSON (over heavier-weight enterprise-level XSD-based canonical models for SOAP-based SOA services) might be more appropriate.


JSON Schema

 
RFC 4627 - The application/json Media Type for JavaScript Object Notation (JSON)


JSON support in JAXB


XMLSpy supports XML-to-JSON conversion
http://www.altova.com/xmlspy/json-editor.html

WordCount

Copyright

© 2001-2026 International Technology Ventures, Inc., All Rights Reserved.