Skip to content

Flask Web App

tharunsikhinam edited this page Jun 11, 2019 · 11 revisions

Description

Flask web application is used to serve the results from MongoDB to the User Interface. The application is also responsible for serving up the static content of the website. All relevant flask files are stored under thenextbestbook/flask

pymongo library is used to connect to the MongoDB

pytest is used for test cases

mongomock is used to mock MongoDB object for test cases

Setup

To start the application run

python run.py

The application starts by default on localhost and Port number 8080

Project Structure

  • config.py: All application related configs such as port number, MongoDB URI are stored in

  • run.py: Used to initialize and launch the application

  • app/__init__.py: Used to create the app context and make the connection to the database.

  • app/controllers/books.py: provides routes to access the books collection

  • app/models/books.py: executes the query on the collection and returns the result

  • tests: contains the test cases for the flask application

API's

GET /books/<book_name>

Description: API to fetch a list of books based on the search query. Returns an array of book titles with book id's

GET /books/similarBooks/<book_id>

Description: API to fetch similar books given a book_id. Return an array of books with title, description, author name, image URL and rating

GET /users/recommendedBooks/<user_id>

Description: API to fetch recommended books for a given user_id. Returns an array of books with title, description, author name, image URL and rating

Clone this wiki locally