A simple api, to demonstrate usage of falcon framework. It uses sqlite for database and sqlalchemy as orm.
You can use virtualenv, pipenv or python builtin venv module to create an environmen. I will be using pipenv:
$ pipenv --python 3.7
$ pipenv shell && pipenv installAfter requirements installation create a database file with command below:
$ python manage.py initdbIf you see this message You have database file in the current directoryto createad it run dropdb, initdb commands respectively. run python manage.py dropdb and python manage.py dropdb commands
Now you have a database and ready to use falcon api. Let`s run the server:
$ python manage.py runserver
* Running on http://localhost:5000/ (Press CTRL+C to quit)
* Restarting with stat
* Debugger is active!
* Debugger PIN: 227-578-359Methods:
$ sudo pip install httpieCalling http methods:
get:
$ http localhost:5000/user username==foo email==foo@bar.com
HTTP/1.0 200 OK
content-length: 39
content-type: application/json; charset=UTF-8
{
"email": "foo@bar",
"username": "foo"
}post:
$ http post localhost:5000/user username=foo email=foo@bar.comdelete:
$ http delete localhost:5000/user username==foo