- Create a "Users" table. A user has an ID (primary key), name, age, location
- Create a POST method for adding new users to the table
- Create a GET method with a query parameter (user id) for retrieving information about a specific user
- Create a GET method for retrieving all the users from the database
User model Snapshot (SQLAlchemy)
class User(db.Model):
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(80), nullable=False)
age = db.Column(db.Integer, nullable=False)
location = db.Column(db.String(80), nullable=False)
email = db.Column(db.String(120), unique=True, nullable=False)
- POST api/users: Create a new user
- GET api/users?id=1: Get a user by id
- GET api/users: Get all users
- Clone the repo
git clone https://github.com/codelawani/toy-api.git
- Create a virtual environment
cd toy-api
python3 -m venv venv
source venv/bin/activate
- Install the requirements
pip install -r requirements.txt
- Add env variables to a .env file -
DB_USER
, DB_PASS
, DB_HOST
, DB_NAME
, DB_PORT
- Run db setup script
db_setup.sh
(make sure you have mysql installed and take a look at the script before running it)
chmod +x db_setup.sh
sudo ./db_setup.sh
- Run the app