JSON is the Ticket!

JSON is the ticket!

JSON interchange between Server and Client

The JSON protocol can be used for REST APIs between different Front-End and Back-End stacks, for example Back-Ends like JAVA Spring, Nodejs or PHP with the Front-End, which is normally Javascript, JS Library or JS Framework.

The JSON protocol (JavaScript Object Notation) is an open standard file and data interchange format that uses human-readable text to store and transmit data objects consisting of attribute–value pairs and arrays (source Wikipedia).

A JSON file can be communicated by way of tools like Fetch, Axios or GraphQ and because of its straightforward data structure, it is easy to debug.

JAVA / Spring

A REST or RESTful API can be applied with a JSON data file between JAVA / Spring server and for example an Axios component in JS React. Especially for PUT(Update an entree in a database) and POST(Create a new entree in to a database) methods work smoothly with the JSON files.

Node.js

For a Node.js server with an Express framework the JSON protocol is in this case again easy to deploy and debug. At both sides, server and client side, you can just use de JS Console.log() to see what data is transferred to and fro.

PHP server

A more special case is a combination of vanilla PHP server and JS Front-End, but also here, JSON protocol serves us well. Because of its legacy (PHP serves Front-END as well as Back-END), using the PHP only as Back-END requires to use the json_encode() and json_decode() functions to exchange the data with the client.

GraphQL

A more modern usage of APIs is the GraphQL query language on both the server and client side, most frequently done with the Apollo platform. Although for the communication between the server and the client the JSON protocol is being used, it is more difficult to see where and how it is applied, because GraphQL is a higher language for API development. Debugging in the classical way (with help of the Console.log() function) is more difficult, but instead a tool called GraphiQL is offered.

As this post pointed out, the JSON protocol is widely used as a data format between the server and client. Regarding the implementation it is recommended to assign a Full-Stack Developer(Back-End and Front-End in one), as long as the project is small/mid-sized or the project structure is not too complicated.

Leave a Reply

Your email address will not be published. Required fields are marked *