Skip to content

A quick howto to setup a flask api that reads from a json file and appends posts

License

Notifications You must be signed in to change notification settings

MrBramme/flask-rest

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

flask-rest API

A quick howto to setup a flask api that reads from a json file and appends posts. This isn't efficient code nor is it error proof. It's mainly a quick setup for testing purposes.

Requirements

Create a venv

virtualenv apiVenv
source apiVenv/bin/activate

Install Flask & Flast-restful

pip install flask
pip install flask-restful

Add your data in data.json, and run the api.

python flask-api.py

Testing the code

Get all: curl https://127.0.0.1:5000/list

Get at index: curl https://127.0.0.1:5000/list/0

Post: curl https://127.0.0.1:5000/list -d '{"name":"newName","label":"newLabel"}' -X POST -H "Content-Type: application/json"

Different data

When using different data, be sure to update the parser in flask-api.py.

parser = reqparse.RequestParser()
parser.add_argument('name')
parser.add_argument('label')

About

A quick howto to setup a flask api that reads from a json file and appends posts

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages