diff --git a/New_APIs/Swiggy API/index.html b/New_APIs/Swiggy API/index.html new file mode 100644 index 0000000..b1f93ce --- /dev/null +++ b/New_APIs/Swiggy API/index.html @@ -0,0 +1,26 @@ + + + + + + + Swiggy Restaurant Finder + + +
+

Swiggy Restaurant Finder

+
+
+
+

Find Restaurants

+ + +
+
+

Restaurant Details

+
+
+
+ + + diff --git a/New_APIs/Swiggy API/index.js b/New_APIs/Swiggy API/index.js new file mode 100644 index 0000000..2dded9d --- /dev/null +++ b/New_APIs/Swiggy API/index.js @@ -0,0 +1,50 @@ +document.addEventListener('DOMContentLoaded', function () { + document.getElementById('fetchRestaurantsButton').addEventListener('click', fetchRestaurants); +}); + +async function fetchRestaurants() { + const location = document.getElementById('location').value; + const endpoint = `https://api.swiggy.com/restaurants?location=${location}`; + + try { + const response = await fetch(endpoint, { + method: 'GET', + headers: { + 'Content-Type': 'application/json', + 'Authorization': 'Bearer YOUR_ACCESS_TOKEN' // Hypothetical access token + } + }); + + if (!response.ok) { + throw new Error(`HTTP error! Status: ${response.status}`); + } + + const data = await response.json(); + console.log('Fetched data:', data); + + if (data.restaurants && data.restaurants.length > 0) { + const randomRestaurant = data.restaurants[Math.floor(Math.random() * data.restaurants.length)]; + displayRestaurant(randomRestaurant); + } else { + displayError('No restaurants found.'); + } + } catch (error) { + console.error('Error fetching restaurant details:', error); + displayError('Failed to fetch restaurant details.'); + } +} + +function displayRestaurant(restaurant) { + const restaurantDiv = document.getElementById('restaurant'); + restaurantDiv.innerHTML = ` +

${restaurant.name}

+

Cuisine: ${restaurant.cuisine}

+

Rating: ${restaurant.rating}

+

Address: ${restaurant.address}

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

${message}

`; +} diff --git a/New_APIs/Swiggy API/manifest.json b/New_APIs/Swiggy API/manifest.json new file mode 100644 index 0000000..6bdf9fe --- /dev/null +++ b/New_APIs/Swiggy API/manifest.json @@ -0,0 +1,15 @@ +{ + "short_name": "SwiggyApp", + "name": "Swiggy Restaurant Finder", + "icons": [ + { + "src": "icon.png", + "type": "image/png", + "sizes": "192x192" + } + ], + "start_url": ".", + "display": "standalone", + "theme_color": "#ff7e5f", + "background_color": "#feb47b" +} diff --git a/New_APIs/Swiggy API/package-lock.json b/New_APIs/Swiggy API/package-lock.json new file mode 100644 index 0000000..60d128b --- /dev/null +++ b/New_APIs/Swiggy API/package-lock.json @@ -0,0 +1,37 @@ +{ + "name": "swiggy-restaurant-finder", + "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" + } + } + } + } + \ No newline at end of file diff --git a/New_APIs/Swiggy API/package.json b/New_APIs/Swiggy API/package.json new file mode 100644 index 0000000..039df32 --- /dev/null +++ b/New_APIs/Swiggy API/package.json @@ -0,0 +1,15 @@ +{ + "name": "swiggy-restaurant-finder", + "version": "1.0.0", + "description": "A simple app to search and display restaurants using Swiggy API", + "main": "index.js", + "scripts": { + "start": "node server.js" + }, + "author": "Your Name", + "license": "ISC", + "dependencies": { + "express": "^4.17.1" + } + } + \ No newline at end of file diff --git a/New_APIs/Swiggy API/style.css b/New_APIs/Swiggy API/style.css new file mode 100644 index 0000000..29bd35a --- /dev/null +++ b/New_APIs/Swiggy API/style.css @@ -0,0 +1,70 @@ +body { + font-family: 'Arial', sans-serif; + background: linear-gradient(135deg, #ff7e5f, #feb47b); + 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: #ff7e5f; +} + +button { + padding: 10px 20px; + font-size: 1em; + color: #fff; + background-color: #ff7e5f; + border: none; + border-radius: 5px; + cursor: pointer; + transition: background-color 0.3s; +} + +button:hover { + background-color: #feb47b; +} + +#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; +}