ankittkamal / ReactEats-backend

A simple node.js web server that fetches data from a third-party (Swiggy) API and exposes it to a client (ReactEats) app.

Home Page:https://react-eats-backend.vercel.app

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ReactEats Web Server

A simple node.js web server that fetches data from a third-party (Swiggy) API and exposes it to a client (ReactEats) app.

Original code by [@Harshitha]

https://github.com/HarshithaSolai/instafood-server

Table of contents:

API Endpoints

  • 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();
  1. 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();

Clone Repository

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.

Deploy your own server

Note : Push your code into your Github Repostory

To deploy our Node.js app on vercel.com, you can follow these steps:

  1. Create an account on https://vercel.com/ if you haven't already.
  2. Click on the Add New button and select Project from the dropdown menu.
  3. Connect to the github repository (node server) which you want to deploy and import the repo
  4. Set the name and don't edit Root directly
  5. Set the Environment Variables and add PORT environment variables to 3000.
  6. Wait for the deployment to finish. Once it's done, you should see a success message and a link to our server url.
  7. Click on the link url to test our server.

Modification and Improvement

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:

  1. Hosted the Node.js server on Vercel, which resulted in significantly faster response times.
  2. 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

Contribute to this repository

If you have any suggestions to improve this node server, please feel free to raise a PR.

About

A simple node.js web server that fetches data from a third-party (Swiggy) API and exposes it to a client (ReactEats) app.

https://react-eats-backend.vercel.app


Languages

Language:JavaScript 100.0%