Skip to content

philippe131/Flask-Rest-API

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Flask-api

This project is a basic flask rest api.

For the potential futur improvements go to the end of the Readme.

Dependencies

  • flask : Python server of choice.
  • flask-marshmallow : Used to serialize object.
  • flask-sqlalchemy : The database.
  • marshmallow-sqlalchemy : Used to make the link between marshmallow and sqlalchemy.
  • Flask-Testing : Pour les tests unitaires

Set up

Install pipenv

pip3 install pipenv

Run pipenv

pipenv shell

Install the Dependencies

pipenv install flask flask-sqlalchemy flask-marshmallow marshmallow-sqlalchemy Flask-Testing

Running the tests

To run the test launch

python test_view.py

Running the app

To run the app, first run the createDb.py file to create the database tables, you only need to do it once unless you change your model definitions

python createDb.py

Run the app itself

python app.py

How to use it (Once the database is created)

To check the fields and the specificities of the Db, go at the end of the Readme

Create a new user, for the date_birth use the format : Day/Month/year

POST request to http://127.0.0.1:5000/users with a json containing the fields of an user.

Recover all the users from the Database or just one

GET request to http://127.0.0.1:5000/users or GET request to http://127.0.0.1:5000/users/<id>

Update a user using his id

PUT request to http://127.0.0.1:5000/users/<id>

Create a new property

POST request to http://127.0.0.1:5000/users with a json

Get all the properties or just one

GET request to http://127.0.0.1:5000/propreties or GET request to http://127.0.0.1:5000/propreties/<id>

Update a property using his id

PUT request to http://127.0.0.1:5000/properties/<id>

Database description

  • user (id = Integer, last_name = String, first_name = String, date_birth = Date)

  • property (id = Integer, name = String, description = String, type = String, city = string, nb_pieces = Integer, feature_pieces = String, owner = String)

You can't insert a property without owner.

Potential futur improvements

  • For the test, automatize the filling of the test data
  • Handle error raised when trying to create a property with an unknow owner.
  • Handle error raised when trying to recover a property / a user which don't exist
  • Allow users to only view properties from one city
  • Restrict access of the users only to their propreties
  • Allow users to delete their properties
  • Allow users to find a properties using other filter like the number of pieces or the name of the owner

About

This project is a basic REST API using Flask

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages