A simple node.js web server that fetches data from a third-party (Swiggy) API and exposes it to a client (ReactEats) app.
https://github.com/HarshithaSolai/instafood-server
-
API Endpoint:
/api/restaurants
-
HTTP Method:
GET
-
Response Format:
JSON
-
URL:
https://react-eats-backend.vercel.app/
-
Example Request:
https://react-eats-backend.vercel.app/api/restaurants
-
Explanation : This API fetches the restaurant data for the given location from Swiggy API [to change location edit the swiggy api from index.js fetch function] and exposes it to the clients. The response format of this API is same as Swiggy API enpoint.
-
Usage : In react app , you can hit this API like mentioned below
fetch(`https://react-eats-backend.vercel.app/api/restaurants`);
Example :
const response = await fetch(
"https://react-eats-backend.vercel.app/api/restaurants"
);
const data = await response.json();
- List all menu items for the given restaurant Id (menuId)
-
API Endpoint:
api/restaurants/resId
-
HTTP Method:
GET
-
Query Parameters:
resId
(required): ID of the restaurant. -
Response Format:
JSON
-
URL:
https://react-eats-backend.vercel.app/api/restaurants/resId
-
Example Request:
https://react-eats-backend.vercel.app/api/restaurants/435678
-
Explanation : This API fetches the restaurant data in json format for the given location from Swiggy API and exposes it to the clients. The response format of this API is same as Swiggy API enpoint.
-
Usage : In react app , you can hit this API like mentioned below
fetch(`https://react-eats-backend.vercel.app/api/restaurants/resId`);
Example :
const response = await fetch(
"https://react-eats-backend.vercel.app/api/restaurants/435678"
);
const data = await response.json();
You need to write the following commands on the terminal screen (in vscode) so that you can run this project locally.
git clone "https://github.com/ankittkamal/ReactEats-backend"
Go to the project directory
cd ReactEats-backend
Install dependencies
npm install
Start the server
npm start
This server should now be running on localhost
.
Note : Push your code into your Github Repostory
To deploy our Node.js app on vercel.com, you can follow these steps:
- Create an account on https://vercel.com/ if you haven't already.
- Click on the
Add New
button and selectProject
from the dropdown menu. Connect
to the github repository (node server) which you want to deploy andimport
the repo- Set the
name
and don't edit Root directly - Set the
Environment Variables
and addPORT
environment variables to3000
. - Wait for the deployment to finish. Once it's done, you should see a success message and a link to our server url.
- Click on the link url to test our server.
Original code by [@Harshitha] was initially deployed on render.com, but I found that the time taken to fetch data from render.com exceeded 2-3 minutes, impacting performance. In an effort to improve the application's speed and efficiency, I made the following changes:
- Hosted the Node.js server on Vercel, which resulted in significantly faster response times.
- Modified the fetch endpoints to use a new Swiggy API menu
api/restaurants/resId
, enhancing the data source and overall functionality of the application.
These modifications were made with the intention of optimizing the application's performance and user experience.
Code Repository by @Harshitha https://github.com/HarshithaSolai/instafood-server
If you have any suggestions to improve this node server, please feel free to raise a PR.