Configuring API using JSON
What is an API? To put it simply, an application programming interface is a way in which we can access our application data and present it in a desired format. The API implementation grants access to its data via application requests. It can be an HTTP request or FTP. With respect to the context of our book, we are going to learn about HTTP requests.
A request basically consists of the following:
- Unique Resource Location (URL)
- Request headers
- Request body
An API server provides an endpoint URL so that we can access the required info through our client, for instance, a browser. In the preceding chapters, we have already seen how node.js implements an API server with its basic core.
Let's see how hapi
implements such an API on top of node.js. To discover this, consider the following code:
const Hapi = require('hapi'); const constants = require('./constants'); const port = constants.port; const server = new Hapi.Server({ port }); server.route({ method: 'GET', path...