Coders Packet

JSON Object retrieving API using Node.js

By Aaradhya Korde

2 RESTful APIs made using node.js that will return the requested data from a JSON file.

The JSON file used for the development is item_list.json from the internet. You can work with any other .json file which has an array of objects in it, all you must do is update the API's for your specific JSON data. However there is no need to change any underlying logic.
NOTE: This packet is just a set of 2 APIs without any frontend, and can work without it.

API 1:
Sends the list of 'n' items specified in query parameter 'size', offset by an amount in query parameter 'page'. The
function is that the list will be paginated based on the request query. This list will only return the the key-value pairs which you update it for.
+ Endpoint = /api/products/list?size={no_of_items}&page={offset}
+ Response = [
{
"key": value,

"key": value,

"key": value
}
...
]

API1Output

 

API 2:

Sends the details of an object based on the requested resource. The object's id will be sent in the request url where it
must be identified and the correct object sent. All the details of the product must be sent.
+ Endpoint = /api/products/:id
+ Response =

{
"key": value,

"key": value,

"key": value
}

API2Output

Download Complete Code

Comments

No comments yet

Download Packet

Reviews Report

Submitted by Aaradhya Korde (AaradhyaKorde)

Download packets of source code on Coders Packet