Chapter 9. JSON on the Server Side
When we talk about web client–server relationships, we can categorize technologies as client side or server side:
- On the client side, we have HTML, CSS, and JavaScript.
- On the server side, there is PHP, ASP.NET, Node.js, Ruby on Rails, Java, Go, and many, many more.
As a web client, we send requests for resources to a server using HTTP. The server responds with a document, such as HTML or JSON. When that document is a JSON document, the server side code must handle the creation of it.
In addition to serving a JSON document, a server may receive a JSON document. We saw this in Chapter 8 when we used HTTP to post a JSON document to the CouchDB web API. When a document is received, the server-side code must handle the parsing of that document.
In previous chapters, we discussed how JavaScript can make behind-the-scenes HTTP requests for JSON resources to web APIs. It’s easy to think of JavaScript playing this role because it is categorized as “client side.” However, JavaScript isn’t the only language that can make HTTP requests for JSON resources. HTTP requests can also be made by a server-side web framework.
In the scenario where JSON is requested by a server-side technology, its role becomes the client. Here are some example scenarios where HTTP requests are made by server-side web framework code:
- Using a web API for data to populate dynamic pages of a website. This could be a public third-party web API or your own private web API such as CouchDB. ...
Get Introduction to JavaScript Object Notation now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.