Skip to content

Practice building a Restful API hooked to a simple SQLite DB using Python Flask, Flask_SQLAlchemy and Flask_restful

Notifications You must be signed in to change notification settings

cheuni02/BookCollections

Repository files navigation

Book Collections API

NOTEs

  • these commands below for now are for macos users only
  • the package manager here is Pip, but you may want to use: Pipenv, Poetry or Conda

Overview

This is just practice in making a simple Restful API using Python Flask with the CRUD HTTP methods for

  • fetching and displaying all books in DB
  • fetching a specific book based on ID (for now)
  • Adding a new book to the DB
  • Amending details of an existing book
  • Deleting a book

Installation

  1. make sure you have Python3+, if not download from https://www.python.org/downloads/
  2. create virtual env to host this API:
% python3 -m venv <name of virtual env>
% 
  1. activate virtual env
% source ./bin/activate
(<name of virtual env>) -> % 
  1. cd into that venv directory
  2. clone repository from this github page
  3. install dependencies via requirements.txt
(<name of virtual env>) -> % pip install -r requirements.txt
  1. make sure to manually test by having a rest client installed e.g. postman: https://www.postman.com/downloads/

Setting up the DB

Data is stored and persisted in ./instance/database.db

(<name of virtual env>) -> % python create_db.py

NOTE: To delete the DB it will have to be done manually

(<name of virtual env>) -> %  rm ./instance/database.db

starting server

 (<name of virtual env>) -> % python main.py

NOTE

main.py contains the entry for running api.py, but you may want to run it in a different way e.g. from the IDE

Testing

Postman collection:

About

Practice building a Restful API hooked to a simple SQLite DB using Python Flask, Flask_SQLAlchemy and Flask_restful

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages