From 230b04a3096495115e2c3be56f9e5cce38d35530 Mon Sep 17 00:00:00 2001 From: Revanth <109272714+revanth1718@users.noreply.github.com> Date: Thu, 8 Aug 2024 11:03:11 +0530 Subject: [PATCH] Zomato API --- New_APIs/Zomato API/README.md | 14 ++++++ New_APIs/Zomato API/index.html | 25 ++++++++++ New_APIs/Zomato API/index.js | 51 +++++++++++++++++++ New_APIs/Zomato API/package-lock.json | 45 +++++++++++++++++ New_APIs/Zomato API/package.json | 15 ++++++ New_APIs/Zomato API/style.css | 70 +++++++++++++++++++++++++++ 6 files changed, 220 insertions(+) create mode 100644 New_APIs/Zomato API/README.md create mode 100644 New_APIs/Zomato API/index.html create mode 100644 New_APIs/Zomato API/index.js create mode 100644 New_APIs/Zomato API/package-lock.json create mode 100644 New_APIs/Zomato API/package.json create mode 100644 New_APIs/Zomato API/style.css diff --git a/New_APIs/Zomato API/README.md b/New_APIs/Zomato API/README.md new file mode 100644 index 0000000..2c06697 --- /dev/null +++ b/New_APIs/Zomato API/README.md @@ -0,0 +1,14 @@ +# Zomato API Viewer App + +A simple web application to interact with the Zomato API and display restaurant data. + +## Features +- Fetch and display random restaurant details + +## Installation +1. Clone the repository: + ```bash + git clone https://github.com/username/ZomatoAPIApp.git + +## Contributor +### Revanth \ No newline at end of file diff --git a/New_APIs/Zomato API/index.html b/New_APIs/Zomato API/index.html new file mode 100644 index 0000000..59d276d --- /dev/null +++ b/New_APIs/Zomato API/index.html @@ -0,0 +1,25 @@ + + + + + + + Zomato API Viewer + + +
+

Zomato API Viewer

+
+
+
+

Find a Restaurant

+ +
+
+

Restaurant Details

+
+
+
+ + + diff --git a/New_APIs/Zomato API/index.js b/New_APIs/Zomato API/index.js new file mode 100644 index 0000000..b5ba734 --- /dev/null +++ b/New_APIs/Zomato API/index.js @@ -0,0 +1,51 @@ +document.addEventListener('DOMContentLoaded', function () { + document.getElementById('fetchRestaurantButton').addEventListener('click', fetchRandomRestaurant); +}); + +async function fetchRandomRestaurant() { + const apiKey = 'https://developers.zomato.com/api/v2.1/restaurant?res_id=56625527'; + const cityId = 280; // Example city ID for San Francisco + const endpoint = `https://developers.zomato.com/api/v2.1/search?entity_id=${cityId}&entity_type=city&count=1&sort=rating&order=desc`; + + try { + const response = await fetch(endpoint, { + method: 'GET', + headers: { + 'Accept': 'application/json', + 'user-key': apiKey + } + }); + + if (!response.ok) { + throw new Error(`HTTP error! Status: ${response.status}`); + } + + const data = await response.json(); + if (data.restaurants && data.restaurants.length > 0) { + const restaurant = data.restaurants[0].restaurant; + displayRestaurant(restaurant); + } else { + displayError('No restaurants found.'); + } + } catch (error) { + console.error('Error fetching restaurant:', error); + displayError('Failed to fetch restaurant details.'); + } +} + +function displayRestaurant(restaurant) { + const restaurantDiv = document.getElementById('restaurant'); + restaurantDiv.innerHTML = ` +

${restaurant.name}

+

Cuisine: ${restaurant.cuisines}

+

Address: ${restaurant.location.address}

+

Rating: ${restaurant.user_rating.aggregate_rating} (${restaurant.user_rating.rating_text})

+

Cost for Two: ${restaurant.currency} ${restaurant.average_cost_for_two}

+ View on Zomato + `; +} + +function displayError(message) { + const restaurantDiv = document.getElementById('restaurant'); + restaurantDiv.innerHTML = `

${message}

`; +} diff --git a/New_APIs/Zomato API/package-lock.json b/New_APIs/Zomato API/package-lock.json new file mode 100644 index 0000000..e6bb010 --- /dev/null +++ b/New_APIs/Zomato API/package-lock.json @@ -0,0 +1,45 @@ +{ + "name": "zomato-api-app", + "version": "1.0.0", + "lockfileVersion": 1, + "requires": true, + "dependencies": { + "express": { + "version": "4.17.1", + "resolved": "https://registry.npmjs.org/express/-/express-4.17.1.tgz", + "integrity": "sha512-G7fYv8zS0D7ftu3gnLsOniwhgLU4k9v+1NEtFPP07/Oa8XJ51FtdUKLqIvsTcZo5ua23NO4s9Hr77BM19DOf1g==", + "requires": { + "accepts": "1.3.7", + "array-flatten": "1.1.1", + "body-parser": "1.19.0", + "content-disposition": "0.5.3", + "cookie": "0.4.0", + "cookie-signature": "1.0.6", + "debug": "2.6.9", + "depd": "1.1.2", + "encodeurl": "1.0.2", + "escape-html": "1.0.3", + "etag": "1.8.1", + "finalhandler": "1.1.2", + "fresh": "0.5.2", + "merge-descriptors": "1.0.1", + "methods": "1.1.2", + "on-finished": "2.3.0", + "parseurl": "1.3.3", + "path-to-regexp": "0.1.7", + "proxy-addr": "2.0.6", + "qs": "6.7.0", + "range-parser": "1.2.1", + "safe-buffer": "5.1.2", + "send": "0.17.1", + "serve-static": "1.14.1", + "setprototypeof": "1.1.1", + "statuses": "1.5.0", + "type-is": "1.6.18", + "utils-merge": "1.0.1", + "vary": "1.1.2" + } + } + } + } + \ No newline at end of file diff --git a/New_APIs/Zomato API/package.json b/New_APIs/Zomato API/package.json new file mode 100644 index 0000000..5b44cd2 --- /dev/null +++ b/New_APIs/Zomato API/package.json @@ -0,0 +1,15 @@ +{ + "name": "zomato-api-app", + "version": "1.0.0", + "description": "A simple app to view restaurant data from the Zomato API", + "main": "index.js", + "scripts": { + "start": "node server.js" + }, + "author": "Revanth", + "license": "ISC", + "dependencies": { + "express": "^4.17.1" + } + } + \ No newline at end of file diff --git a/New_APIs/Zomato API/style.css b/New_APIs/Zomato API/style.css new file mode 100644 index 0000000..1119f11 --- /dev/null +++ b/New_APIs/Zomato API/style.css @@ -0,0 +1,70 @@ +body { + font-family: 'Arial', sans-serif; + background: linear-gradient(135deg, #ff8c00, #ffc107); + color: #333; + margin: 0; + display: flex; + flex-direction: column; + align-items: center; + justify-content: center; + min-height: 100vh; +} + +header { + text-align: center; + margin-bottom: 20px; +} + +header h1 { + font-size: 3em; + color: #fff; +} + +main { + background: rgba(255, 255, 255, 0.9); + padding: 20px; + border-radius: 10px; + box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1); + text-align: center; +} + +section { + margin-bottom: 20px; +} + +h2 { + font-size: 2em; + margin-bottom: 10px; + color: #ff8c00; +} + +button { + padding: 10px 20px; + font-size: 1em; + color: #fff; + background-color: #ff8c00; + border: none; + border-radius: 5px; + cursor: pointer; + transition: background-color 0.3s; +} + +button:hover { + background-color: #e07b00; +} + +#restaurant-info { + margin-top: 20px; +} + +#restaurant { + font-size: 1.2em; + background: #fff; + padding: 20px; + border-radius: 10px; + box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1); +} + +#restaurant p { + margin: 10px 0; +}