Documentation: Backend API - GITANG1/SE-Yelp GitHub Wiki

Backend API

User API

  1. User Register API
  2. User Authenticate API
  3. User Update API

1. Restaurants Listing API

  GET restaurants/list

Returns List of all the restaurants in the database.

Example Request:

  GET restaurants/list

Example Response:

  [
    {
        "_index": "gulp",
        "_type": "restaurants",
        "_id": "5",
        "_score": 1,
        "_source": {
            "name": "The Spot",
            "city": "Gainesville",
            "menu": [
                "the gyro",
                "spanikopita",
                "greek salad"
            ],
            "location": "29.6526250, -82.3464950",
            "tags": [
                "breakfast",
                "lunch",
                "dinner",
                "take out",
                "nightlife"
            ],
            "imageUrl": [
                "images/5/1.jpg",
                "images/5/2.jpg",
                "images/5/3.jpg"
            ],
            "menuUrl": "images/5/menu.jpg",
            "logoUrl": "images/5/logo.jpg",
            "hours": "10 AM to 10 PM",
            "rating": {
                "total": 22,
                "number": 5,
                "value": 4.4
            },
            "address": "16 NW 18th St Gainesville, FL 32603",
            "phoneNo": "(352) 834 5894",
            "costInfo": "$",
            "cuisine": "Greek, Sandwiches, Mediterranean",
            "website": "www.thespotgainesville.com"
        }
    },
    {
        "_index": "gulp",
        "_type": "restaurants",
        "_id": "8",
        "_score": 1,
        "_source": {
            "name": "The smoothie room",
            "city": "Orlando",
            "menu": [
                "berry dose",
                "papaya love",
                "yellow fever"
            ],
            "location": "28.5152260, -81.3776900",
            "tags": [
                "breakfast",
                "lunch",
                "take out"
            ],
            "imageUrl": [
                "images/8/1.jpg",
                "images/8/2.jpg",
                "images/8/3.jpg"
            ],
            "menuUrl": "images/8/menu.jpg",
            "logoUrl": "images/8/logo.png",
            "hours": "10 AM to 5 PM",
            "rating": {
                "total": 20,
                "number": 5,
                "value": 4
            },
            "address": "25 W Crystal Lake St, Orlando, FL 32806",
            "phoneNo": "(352) 834 5894",
            "costInfo": "$",
            "cuisine": "Juice Bars & Smoothies, Live/Raw Food, Vegan",
            "website": "www.thesmoothieroom.com"
        }
    }
  ]

Status Codes

  • 200: No error
  • 500: Internal Server Error

2. Restaurants Searching API

 POST restaurants/search/

Search restaurants on the basis of a search string and city location.

Example Request:

    POST restaurants/search/
    Content-Type: application/json

    {
        "search": "Pizza Hut",
        "city": "Gainesville"
    }

Example Response:

    HTTP/1.1 200 OK
    Content-Type: application/json
    [
        {
            "_index": "gulp",
            "_type": "restaurants",
            "_id": "2",
            "_score": 3.9899054,
            "_source": {
                "name": "pizza hut",
                "city": "gainesville",
                "menu": [
                    "veggie pizza",
                    "chicken pizza"
                ],
                "location": "29.655272, -82.420424",
                "tags": [
                    "breakfast",
                    "lunch",
                    "dinner",
                    "take out",
                    "delivery"
                ],
                "imageUrl": [
                    "images/2/1.jpg",
                    "images/2/2.jpg",
                    "images/2/3.jpg"
                ],
                "menuUrl": "images/2/menu.jpg",
                "logoUrl": "images/2/logo.png",
                "hours": "10 AM to 10 PM",
                "rating": {
                    "total": 20,
                    "number": 5,
                    "value": 4
                },
                "address": "3802 sw 34th st, gainesville",
                "phoneNo": "(352) 834 5894",
                "costInfo": "$$",
                "cuisine": "Fast food/ American",
                "website": "www.pizzahut.com"
            }
        },
        {
            "_index": "gulp",
            "_type": "restaurants",
            "_id": "1",
            "_score": 2.3898983,
            "_source": {
                "name": "blaze pizza",
                "city": "gainesville",
                "menu": [
                    "veggie pizza",
                    "chicken pizza"
                ],
                "location": "29.62170, -82.37230",
                "tags": [
                    "breakfast",
                    "lunch",
                    "dinner"
                ],
                "imageUrl": [
                    "images/1/1.jpg",
                    "images/1/2.jpg",
                    "images/1/3.jpg"
                ],
                "menuUrl": "images/1/menu.jpg",
                "logoUrl": "images/1/logo.png",
                "hours": "10 AM to 10 PM",
                "rating": {
                    "total": 25,
                    "number": 5,
                    "value": 5
                },
                "address": "3800 sw 34th st, gainesville",
                "phoneNo": "(352) 834 5894",
                "costInfo": "$$",
                "cuisine": "Fast food/ American",
                "website": "www.blazepizza.com"
            }
        },
    ]

JSON parameters:

  • search(optional): The string to be searched for in the restaurant names/ restaurant menu
  • city: The string that represents the city in the which the restaurants have to be searched

Status Codes

  • 200: No error
  • 400: Bad parameter
  • 500: Internal Server Error

3. Restaurant Details API

    GET restaurants/restID/:restID

Returns all data for restaurant with a particular restaurantID

Example Request:

    GET restaurants/restID/1

Example Response:

    HTTP/1.1 200 OK
    Content-Type: application/json
    [
        {
            "_index": "gulp",
            "_type": "restaurants",
            "_id": "1",
            "_score": 1,
            "_source": {
                "name": "blaze pizza",
                "city": "gainesville",
                "menu": [
                    "veggie pizza",
                    "chicken pizza"
                ],
                "location": "29.62170, -82.37230",
                "tags": [
                    "breakfast",
                    "lunch",
                    "dinner"
                ],
                "imageUrl": [
                    "images/1/1.jpg",
                    "images/1/2.jpg",
                    "images/1/3.jpg"
                ],
                "menuUrl": "images/1/menu.jpg",
                "logoUrl": "images/1/logo.png",
                "hours": "10 AM to 10 PM",
                "rating": {
                    "total": 25,
                    "number": 5,
                    "value": 5
                },
                "address": "3800 sw 34th st, gainesville",
                "phoneNo": "(352) 834 5894",
                "costInfo": "$$",
                "cuisine": "Fast food/ American",
                "website": "www.pizzahut.com"
            }
        }
    ]

URL Parameters:

  • restID : The id of the restaurant whose details are to be requested.

Status Codes

  • 200: No error
  • 500: Internal Server Error

4. Restaurant Search by Geolocation API

    POST restaurants/searchByLocation/

Search restaurants on the basis of a search string and city location.

Example Request:

    POST restaurants/searchByLocation/
    Content-Type: application/json
    {
        "search" : "pizza hut",
        "location" : "29.655272, -82.420424"
    }

Example Response:

    HTTP/1.1 200 OK
    Content-Type: application/json
    [
        {
            "_index": "gulp",
            "_type": "restaurants",
            "_id": "2",
            "_score": 3.9899054,
            "_source": {
                "name": "pizza hut",
                "city": "gainesville",
                "menu": [
                    "veggie pizza",
                    "chicken pizza"
                ],
                "location": "29.655272, -82.420424",
                "tags": [
                    "breakfast",
                    "lunch",
                    "dinner",
                    "take out",
                    "delivery"
                ],
                "imageUrl": [
                    "images/2/1.jpg",
                    "images/2/2.jpg",
                    "images/2/3.jpg"
                ],
                "menuUrl": "images/2/menu.jpg",
                "logoUrl": "images/2/logo.png",
                "hours": "10 AM to 10 PM",
                "rating": {
                    "total": 20,
                    "number": 5,
                    "value": 4
                },
                "address": "3802 sw 34th st, gainesville",
                "phoneNo": "(352) 834 5894",
                "costInfo": "$$",
                "cuisine": "Fast food/ American",
                "website": "www.pizzahut.com"
            }
        },
        {
            "_index": "gulp",
            "_type": "restaurants",
            "_id": "1",
            "_score": 2.3898983,
            "_source": {
                "name": "blaze pizza",
                "city": "gainesville",
                "menu": [
                    "veggie pizza",
                    "chicken pizza"
                ],
                "location": "29.62170, -82.37230",
                "tags": [
                    "breakfast",
                    "lunch",
                    "dinner"
                ],
                "imageUrl": [
                    "images/1/1.jpg",
                    "images/1/2.jpg",
                    "images/1/3.jpg"
                ],
                "menuUrl": "images/1/menu.jpg",
                "logoUrl": "images/1/logo.png",
                "hours": "10 AM to 10 PM",
                "rating": {
                    "total": 25,
                    "number": 5,
                    "value": 5
                },
                "address": "3800 sw 34th st, gainesville",
                "phoneNo": "(352) 834 5894",
                "costInfo": "$$",
                "cuisine": "Fast food/ American",
                "website": "www.blazepizza.com"
            }
        },
    ]

JSON parameters:

  • search(optional): The string to be searched for in the restaurant names/ restaurant menu
  • location: The string that represents the geo-location around which the restaurants have to be searched. It must be of the type "latitude, longitude".

Status Codes

  • 200: No error
  • 400: Bad parameter
  • 500: Internal Server Error

5. Restaurant Search by Tags API

    POST restaurants/Search/

Search restaurants on the basis of a search string and city location.

Example Request:

    POST restaurants/Search/
    Content-Type: application/json
    {
        "search" : "pizza hut",
        "location" : "29.655272, -82.420424"
    }

Example Response

    HTTP/1.1 200 OK
    Content-Type: application/json
    [
        {
            "_index": "gulp",
            "_type": "restaurants",
            "_id": "2",
            "_score": null,
            "_source": {
                "name": "pizza hut",
                "city": "gainesville",
                "menu": [
                    "veggie pizza",
                    "chicken pizza"
                ],
                "location": "29.655272, -82.420424",
                "tags": [
                    "breakfast",
                    "lunch",
                    "dinner",
                    "take out",
                    "delivery"
                ],
                "imageUrl": [
                    "images/2/1.jpg",
                    "images/2/2.jpg",
                    "images/2/3.jpg"
                ],
                "menuUrl": "images/2/menu.jpg",
                "logoUrl": "images/2/logo.png",
                "hours": "10 AM to 10 PM",
                "rating": {
                    "total": 20,
                    "number": 5,
                    "value": 4
                },
                "address": "3802 sw 34th st, gainesville",
                "phoneNo": "(352) 834 5894",
                "costInfo": "$$",
                "cuisine": "Fast food/ American",
                "website": "www.pizzahut.com"
            },
            "sort": [
                4
            ]
        }
    ]

JSON parameters:

  • tag(optional): The string to be searched for in the restaurant tags.
  • city: The string that represents the city in which the restaurants have to be searched.

Status Codes

  • 200: No error
  • 400: Bad parameter
  • 500: Internal Server Error

Ratings API

1. Ratings Listing by Restaurant API

  GET ratings/:restId

Returns List of all the ratings of a particular restaurant.

Example Request:

  GET ratings/1

Example Response:

    HTTP/1.1 200 OK
    Content-Type: application/json
    [
        {
            "_index": "gulp",
            "_type": "ratings",
            "_id": "AWAAg0OvibPDEf0bYNM0",
            "_score": 0.2876821,
            "_source": {
                "restaurant": {
                    "id": "1",
                    "name": "blaze pizza",
                    "logoUrl": "images/1/logo.png"
                },
                "user": {
                    "id": "2",
                    "name": "Jane Doe"
                },
                "value": 3.5,
                "review": "decent food, great atmosphere"
            }
        }
    ]

URL Parameters:

  • restId : The id of the restaurant whose ratings are to be requested.

Status Codes

  • 200: No error
  • 500: Internal Server Error

2. Ratings Listing by User API

  GET ratings/byUser/:userId

Returns List of all the ratings by a particular user.

Example Request:

  GET ratings/byUser/2

Example Response:

    HTTP/1.1 200 OK
    Content-Type: application/json
    [
        {
            "_index": "gulp",
            "_type": "ratings",
            "_id": "AWAAg0OvibPDEf0bYNM0",
            "_score": 0.2876821,
            "_source": {
                "restaurant": {
                    "id": "1",
                    "name": "blaze pizza",
                    "logoUrl": "images/1/logo.png"
                },
                "user": {
                    "id": "2",
                    "name": "Jane Doe"
                },
                "value": 3.5,
                "review": "decent food, great atmosphere"
            }
        }
    ]

URL Parameters:

  • userId : The id of the user whose ratings are to be requested.

Status Codes

  • 200: No error
  • 500: Internal Server Error

3. Ratings Insert API

 POST ratings/

Insert rating into the database.

Example Request:

    POST ratings/
    Content-Type: application/json

    {
        "restaurant": {
            "id":1,
            "name":"blaze pizza",
            "logoUrl":"images/1/logo.png"
        },
        "user":{
            "id":"2",
            "name":"Jane Doe"
        },
        "value": 3.5,
        "review":"decent food, great atmosphere"
    }

Example Response:

    HTTP/1.1 201 Created
    Content-Type: text/html
    rating added

JSON parameters:

  • restaurant: The details of the restaurant in the form of a JSON including the fields id, name and logoUrl.
  • user: The details of the user in the form of a JSON including the fields id and name.
  • value: The value of the rating in float.
  • review(optional): The review by the user.

Status Codes

  • 201: No error, created
  • 400: Bad parameter
  • 500: Internal Server Error

4. Ratings Delete API

 DELETE ratings/:ratingId

Delete rating from the database.

Example Request:

 DELETE ratings/15

Example Response:

    HTTP/1.1 200 OK
    Content-Type: text/html
    deleted successfully

URL Parameters:

  • ratingId : The id of the rating which is to be deleted.

Status Codes

  • 200: No error
  • 500: Internal Server Error

Checkin API

1. Checkin Listing by User API

  GET checkin/:userId

Returns List of all the checkins by a particular user.

Example Request:

  GET checkin/2

Example Response:

    HTTP/1.1 200 OK
    Content-Type: application/json
    [
        {
            "_index": "gulp",
            "_type": "checkin",
            "_id": "AWAAmBaDibPDEf0bYNNY",
            "_score": 0.2876821,
            "_source": {
                "restaurant": {
                    "id": "1",
                    "name": "blaze pizza",
                    "logoUrl": "images/1/logo.png"
                },
                "user": {
                    "id": "2",
                    "name": "Jane Doe"
                },
                "date": "27/11/2017"
            }
        }
    ]

URL Parameters:

  • userId : The id of the user whose checkins are to be requested.

Status Codes

  • 200: No error
  • 500: Internal Server Error

2. Checkin by User for particular Restaurant API

  GET checkin/:restId/:userId

Returns 0/1 depending upon whether user has checkin in particular restaurant. If checkin exists return 1, else returns 0.

Example Request:

  GET checkin/1/2

Example Response:

    HTTP/1.1 200 OK
    Content-Type: application/json
    "1"

URL Parameters:

  • userId : The id of the user whose checkin is requested.
  • userId : The id of the restaurant whose checkin is requested.

Status Codes

  • 200: No error
  • 500: Internal Server Error

3. Checkin Insert API

 POST checkin/

Insert rating into the database.

Example Request:

    POST checkin/
    Content-Type: application/json

    {
        "restaurant": {
            "id":1,
            "name":"blaze pizza",
            "logoUrl":"images/1/logo.png"
        },
        "user":{
            "id":"2",
            "name":"Jane Doe"
        }
    }

Example Response:

    HTTP/1.1 201 Created
    Content-Type: text/html
    checkin added

JSON parameters:

  • restaurant: The details of the restaurant in the form of a JSON including the fields id, name and logoUrl.
  • user: The details of the user in the form of a JSON including the fields id and name.

Status Codes

  • 201: No error, created
  • 400: Bad parameter
  • 500: Internal Server Error

User API

1. User Register API

 POST user/register/

Add new User. Returns boolean true/false to indicate success/failure in registration.

Example Request:

    POST user/register/
    Content-Type: application/json
    {
        "name":"Jane Doe",
        "username":"jane.doe",
        "email":"[email protected]",
        "password":"12345"
    }

Example Response:

    HTTP/1.1 201 Created
    Content-Type: application/json
    {
        "success": true,
        "msg": "User registered"
    }

JSON parameters:

  • name: The string representing name of user to be registered.
  • username: The string representing username of user to be registered. To be used to authenticate.
  • email: The string representing email of user to be registered.
  • password: The string representing password of user to be registered. To be used to authenticate.

Status Codes

  • 200: No error
  • 201: Created
  • 400: Bad parameter
  • 500: Internal Server Error

2. User Authenticate API

 POST user/authenticate/

Authenticate User and respond with JWT Token. Returns boolean true in success field if user authenticated and false if user cannot be authenticated.

Example Request:

    POST user/authenticate/
    Content-Type: application/json
    {
        "username":"jane.doe",
        "password":"12345"
    }

Example Response:

    HTTP/1.1 200 OK
    Content-Type: application/json
    {
        "success": true,
        "token": "JWT eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJkYXRhIjp7Il9pbmRleCI6Imd1bHAiLCJfdHlwZSI6InVzZXJzIiwiX2lkIjoiQVdBQXVNUHRpYlBERWYwYllOTmEiLCJfc2NvcmUiOjAuMjg3NjgyMSwiX3NvdXJjZSI6eyJuYW1lIjoiSmFuZSBEb2UiLCJlbWFpbCI6ImphbmVAZG9lLmNvbSIsInVzZXJuYW1lIjoiamFuZS5kb2UiLCJwYXNzd29yZCI6IiQyYSQxMCRxWk8yQi5sLjd0bnZPNTlSSlJMdHlPVVI4cTVXYzgzNzNiSzVHdHhpZlVpU3R0RGJEUEVidSJ9fSwiaWF0IjoxNTExODQxMTUyfQ.MlsRfSH_h2eb-dU2qT6z2xmzWMTkT0jbcPlhb2YvVwY",
        "user": {
            "id": "AWAAuMPtibPDEf0bYNNa",
            "name": "Jane Doe",
            "username": "jane.doe",
            "email": "[email protected]"
        }
    }

JSON parameters:

  • username: The string representing username of user to authenticate.
  • password: The string representing password of user to authenticate. Compared with password hash corresponding to given username to authenticate.

Status Codes

  • 200: No error
  • 400: Bad parameter
  • 500: Internal Server Error

3. User Update API

 POST user/update/

Update User information.

Example Request:

    POST user/update/
    Content-Type: application/json
    {
        "id":"AWAA3EEaibPDEf0bYNNc",
        "name":"jane.doe",
        "email":"[email protected]",
        "password":"12345"
    }

Example Response:

    HTTP/1.1 200 OK
    Content-Type: text/html
    User updated successfully!

JSON parameters:

  • id: The string representing id of the user that is to be updated.
  • name: The string representing new name of user to update.
  • email: The string representing new email of user to update.
  • password(optional): The string representing new password of user to update.

Status Codes

  • 200: No error
  • 400: Bad parameter
  • 500: Internal Server Error