├── .gitignore ├── LICENSE ├── README.md ├── package.json ├── views ├── search.css ├── search.html ├── zomato.css └── zomato.ejs └── zomato.js /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | 3 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 anandpatel 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Zomato-API 2 | 3 | In this project, I have used Zomato-API (https://developers.zomato.com/) to get the details of restaurants present in a particular location. You'll be asked a location to fetch the details like **average cost for two people, price ranges, has online delivery or not, and cuisines** of that location. 4 | 5 | ## Requirements 6 | 7 | ### NodeJS and npm 8 | 9 | If you're using Linux-based OS, install the latest version of Nodejs and npm, by typing the following commands on your terminal. 10 | ``` 11 | sudo apt update 12 | sudo apt install build-essential apt-transport-https lsb-release ca-certificates curl 13 | 14 | ``` 15 | 16 | Then, for the **Latest** release (version 12), add this PPA, by typing the following command on your terminal 17 | ``` 18 | curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash - 19 | sudo apt install nodejs 20 | ``` 21 | 22 | Now, you need to install necessary dependencies using npm (node-package-manager), open your termial, and first type
23 | `npm init` to initialize **package.json** file. Then, type
24 | ``` 25 | npm install body-parser ejs express iplocation path public-ip zomato --save 26 | ``` 27 | 28 | ### How to Run? 29 | 30 | Now, navigate to `server.js` file on your terminal, and run the following command to start your localhost server 31 | ``` 32 | node server.js 33 | ``` 34 | 35 | ### Endpoints 36 | 37 | - **/categories**
38 | - This endpoint presents you a list of all restaurants categorized under a particular restaurant type. 39 | 40 | - **/geocode**
41 | - This endpoint takes **latitude and longitude** to get the list of popular Cuisines, Foodie, Nightlife-index and nearby restaurants using your public IP address. 42 | 43 | - **/search**
44 | - This endpoint takes a location, and gives you the precise restaurant suggestions, using `/geocode` endpoint. 45 | 46 | Now, open your browser, and type
47 | http://localhost:{PORT}/{YOUR_ENDPOINT} to get the required details. 48 | 49 | Happy coding ): 50 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "zomato", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "zomato_api.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "author": "anand", 10 | "license": "MIT", 11 | "dependencies": { 12 | "ejs": "^2.6.2", 13 | "express": "^4.17.1", 14 | "zomato": "^1.1.0" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /views/search.css: -------------------------------------------------------------------------------- 1 | body{ 2 | background-image: url('https://www.xmple.com/wallpaper/gradient-linear-red-grey-1920x1080-c2-ff0000-778899-a-15-f-14.svg'); 3 | background-size: cover; 4 | background-attachment: fixed; 5 | } 6 | .center_div{ 7 | padding: 11vw; 8 | margin-left: 10vw; 9 | margin-right: 10vw; 10 | /*background-color: white;*/ 11 | background: rgba(171, 205, 239, 0.3) 12 | } 13 | * { 14 | box-sizing: border-box; 15 | } 16 | 17 | form.example input[type=text] { 18 | padding: 10px; 19 | font-size: 17px; 20 | border: 1px solid grey; 21 | float: left; 22 | width: 80%; 23 | background: #f1f1f1; 24 | } 25 | form.example button { 26 | float: left; 27 | width: 20%; 28 | padding: 10px; 29 | background: #2196F3; 30 | color: white; 31 | font-size: 17px; 32 | border: 1px solid grey; 33 | border-left: none; 34 | cursor: pointer; 35 | } 36 | form.example button:hover { 37 | background: #0b7dda; 38 | } 39 | 40 | form.example::after { 41 | content: ""; 42 | clear: both; 43 | display: table; 44 | } 45 | .place{ 46 | margin-left: 18vw; 47 | } 48 | @media only screen and (max-width: 1125px) { 49 | .tab{ 50 | padding: 20vw; 51 | } 52 | .place{ 53 | margin-left: 14vw; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /views/search.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Zomato.com 5 | 6 | 7 | 8 | 9 | 10 | 13 |
14 | 15 |
16 |
17 |
18 |

Search your place...

19 |
20 | 26 | 27 |
28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /views/zomato.css: -------------------------------------------------------------------------------- 1 | body{ 2 | margin: 0; 3 | background: #e5e5e5; 4 | 5 | } 6 | .header h1{ 7 | text-align: center; 8 | font-family: 'Lato', sans-serif; 9 | color: #fff; 10 | } 11 | .header{ 12 | background-color: red; 13 | padding: 2px; 14 | 15 | } 16 | .content img{ 17 | width: 430px; 18 | height: 300px; 19 | border-radius: 15px; 20 | } 21 | .content{ 22 | height: 300px; 23 | background-color: white; 24 | margin: 0vw 9.8vw; 25 | border-radius: 12px 0px 0px 10px; 26 | } 27 | .text{ 28 | margin: -23vw 0px 0px 31.7vw; 29 | } 30 | .text h1{ 31 | font-size: 28px; 32 | color: red; 33 | } 34 | .text p{ 35 | font-size: 20px; 36 | font-weight: bold; 37 | } 38 | .details{ 39 | margin-left:89px; 40 | } 41 | .key{ 42 | padding-right: 20px; 43 | font-size: 20px; 44 | } 45 | form.example input[type=text] { 46 | padding: 10px; 47 | font-size: 17px; 48 | border: 1px solid grey; 49 | float: left; 50 | width: 80%; 51 | background: #f1f1f1; 52 | border-radius: 20px; 53 | } 54 | form.example button { 55 | float: left; 56 | width: 20%; 57 | padding: 10px; 58 | background: #2196F3; 59 | color: white; 60 | font-size: 17px; 61 | border: 1px solid grey; 62 | border-left: none; 63 | cursor: pointer; 64 | border-radius: 20px; 65 | } 66 | form.example button:hover { 67 | background: #0b7dda; 68 | } 69 | * { 70 | box-sizing: border-box; 71 | } 72 | .search_bar2{ 73 | display: -webkit-flex; /* Safari */ 74 | display: flex; 75 | margin-left: 60vw; 76 | margin-top: -40px; 77 | } 78 | 79 | 80 | 81 | 82 | @media only screen and (max-width: 1125px) { 83 | .content img{ 84 | width: 310px; 85 | height: 290px; 86 | border-radius: 15px; 87 | } 88 | .text p{ 89 | font-size: 15px; 90 | font-weight: bold; 91 | } 92 | .text{ 93 | margin: -31vw 0px 0px 30vw; 94 | } 95 | .content{ 96 | height: 295px; 97 | margin: 0vw 6vw; 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /views/zomato.ejs: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Zomato 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 |

Zomato

15 |
16 |
17 | 18 | 19 |
20 |
21 |
22 |
23 |
24 | <% for (var i of data) { %> 25 | 26 |
27 |
28 | <% if (i.featured_image!= ''){ %> 29 | 30 | 31 | <% } else { %> 32 | 33 | <% } %> 34 | 35 |
36 |
37 |

<%= i.name %>

38 |

<%= i.address %>

39 |
40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 |
Average Cost For Two:<%= i.average_cost_for_two %>
Price Range:<%= i.price_range %>
Has Online Delivery:<%= i.has_online_delivery %>
Cuisines:<%= i.cuisines %>
62 |
63 | 64 | 65 |
66 |
67 |
68 | 69 | <% } %> 70 | 71 | 72 | 73 | -------------------------------------------------------------------------------- /zomato.js: -------------------------------------------------------------------------------- 1 | const express = require("express"); 2 | const zomato = require("zomato"); 3 | const app = express(); 4 | const ejs = require('ejs') 5 | const bodyParser = require("body-parser"); 6 | app.use(express.static(__dirname + '/views')); 7 | 8 | app.use(bodyParser.urlencoded({ extended: true})); 9 | 10 | const client = zomato.createClient({userKey: '176bd0663551ddcc4cea2fcb9dc809bf'}) 11 | 12 | app.set('view engine', 'ejs') 13 | // getLocations and geocode 14 | 15 | app.get("/search_data", (req, res) =>{ 16 | res.sendFile(__dirname + '/views/search.html'); 17 | }) 18 | 19 | app.post("/locations", (req, res)=>{ 20 | let name = req.body.search; 21 | // console.log(name); 22 | client.getLocations({query: name,}, (err, result) =>{ 23 | if(!err){ 24 | let main_data = JSON.parse(result).location_suggestions; 25 | 26 | let latitude = JSON.stringify (main_data[0].latitude); 27 | let longitude = JSON.stringify (main_data[0].longitude); 28 | // console.log(lat); 29 | // console.log(lon); 30 | client.getGeocode({lat:latitude, lon:longitude},(err, result)=>{ 31 | if(!err){ 32 | // console.log(result); 33 | // res.send(result); 34 | let data = JSON.parse(result).nearby_restaurants; 35 | let data_list = []; 36 | for(var i of data){ 37 | var Dict = { 38 | name: i.restaurant.name, 39 | address: i.restaurant.location.address, 40 | average_cost_for_two: i.restaurant.average_cost_for_two, 41 | price_range: i.restaurant.price_range, 42 | has_online_delivery: i.restaurant.has_online_delivery, 43 | cuisines: i.restaurant.cuisines, 44 | featured_image: i.restaurant.featured_image, 45 | url: i.restaurant.url 46 | } 47 | data_list.push(Dict); 48 | } 49 | // console.log(data_list); 50 | res.render('zomato.ejs', {data: data_list}) 51 | }else{ 52 | console.log(err); 53 | } 54 | }) 55 | }else{ 56 | console.log(err); 57 | } 58 | }) 59 | }); 60 | 61 | 62 | app.listen(3031); 63 | console.log("success.....") 64 | --------------------------------------------------------------------------------