Skip to content

anuschka/python-rest-flask

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Flask Rest API

This code is a self explanatory code, I got from here.

The current repository helps in getting started with the basic REST API Development in Flask. The sole existence of this repo is for a Powercoders lecture. The application uses chinook.db that students used in the SQL workshop.

Prerequisites

  • a computer with Python installed
  • virtual environment (which is a copy of the Python interpreter onto which you can install packages privately, without affecting the global Python interpreter installed in your system)

Virtual Environment

  • on Python 3:
python3 -m venv virtual-environment-name
  • on Python 2:
sudo pip install virtualenv
  • to start using a virtual environment, you have to “activate” it:
source venv/bin/activate

Run the code

  • Clone this repository.
git clone https://github.com/anuschka/python-rest-flask.git
  • cd into python-rest-flask
  • Install the requirements
pip install -r requirements.txt
  • Setup environment variables
FLASK_APP=app.py
FLASK_DEBUG=True
  • Run Flask
flask run

Test the code

There are three endpoints in the application:

To create a new record in the Employees table:

curl -H "Content-Type: application/json" -X POST -d '{"LastName":"Power","FirstName":"Coder","Title":"Developer","ReportsTo":"Matthias","BirthDate":"1.1.1990","HireDate":"20.9.2017","Address":"GarageHub","City":"Zurich","Country":"Switzerland","State":"None","PostalCode":"8100","Phone":"0123456789","Fax":"0123456789","Email":"coder@powercoders.com"}' http://127.0.0.1:5000/employees

To delete Employee whose employee ID is 8:

curl -H "Content-Type: application/json" -X DELETE -v http://127.0.0.1:5000/employees/8

About

Basic RESTful API using Flask and Python

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages