-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #393 from sreevidya-16/master
Swiggy API
- Loading branch information
Showing
6 changed files
with
213 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<link rel="stylesheet" href="style.css"> | ||
<title>Swiggy Restaurant Finder</title> | ||
</head> | ||
<body> | ||
<header> | ||
<h1>Swiggy Restaurant Finder</h1> | ||
</header> | ||
<main id="app"> | ||
<section> | ||
<h2>Find Restaurants</h2> | ||
<input type="text" id="location" placeholder="Enter location"> | ||
<button id="fetchRestaurantsButton">Search Restaurants</button> | ||
</section> | ||
<section id="restaurant-info"> | ||
<h2>Restaurant Details</h2> | ||
<div id="restaurant"></div> | ||
</section> | ||
</main> | ||
<script src="index.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 = ` | ||
<h3>${restaurant.name}</h3> | ||
<p><strong>Cuisine:</strong> ${restaurant.cuisine}</p> | ||
<p><strong>Rating:</strong> ${restaurant.rating}</p> | ||
<p><strong>Address:</strong> ${restaurant.address}</p> | ||
`; | ||
} | ||
|
||
function displayError(message) { | ||
const restaurantDiv = document.getElementById('restaurant'); | ||
restaurantDiv.innerHTML = `<p>${message}</p>`; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |