RESTful HTTP API using Flask, Flask-Restful and SQLAlchemy
cd app
- Install requisite packages:
$ make install
- Config file:
settings.py
(default) or set env variableCARCERES_CONFIG
eg:
$ CARCERES_CONFIG=/path/to/my_config.py
$ export CARCERES_CONFIG
- Create tables:
$ make init_db
- Run service:
$ make run
- List of endpoints:
/api/login
(Methods: any) Authorize user by login/pass. Returns tokens./api/refresh
(Methods:POST
) Authorize user by refresh token. Returns tokens./api/user
(Methods:GET
,PUT
) Current user's data./api/client
(Methods:GET
,PUT
) Current client's data./api/users
(Methods:GET
POST
GET /<id>
PUT /<id>
DELETE /<id>
) User resource./api/clients
(Methods:GET
POST
GET /<id>
PUT /<id>
DELETE /<id>
) Client resource./api/cars
(Methods:GET
POST
GET /<id>
PUT /<id>
DELETE /<id>
) Car resource./api/zones
(Methods:GET
POST
GET /<id>
PUT /<id>
DELETE /<id>
) Zone resource./api/places
(Methods:GET
POST
GET /<id>
PUT /<id>
DELETE /<id>
) Place resource./api/subscriptions
(Methods:GET
POST
GET /<id>
PUT /<id>
DELETE /<id>
) Subscription resource.
To authorize send username and password (Basic auth) to /api/login
.
$ curl -u user_name:user_pass http://<url>/api/login
In response you will get a access and refresh tokens. To authenticate in resources endpoints put access token to x-access-tokens
header's field.
$ curl -H "x-access-tokens: <token>" http://<url>/api/users/1
To refresh tokens send a valid refresh token to /api/refresh
.
$ curl -H "Content-Type: application/json" --request POST -d'{refresh_token:"<tok>"}' http://<url>/api/refresh
Don't forget add Content-Type: application/json
header to your requests!
All requests (except authorization requests) require a set x-access-tokens
header.
In requests to resource's endpoints (method GET
) you can set additional parameters:
start
- first returned elem from list (default: 1)limit
- max returned elements (default: 25 orDEFAULT_PAGE_LIMIT
in config field)sort_by
- coma separated list of table fields, useasc(field)
,desc(field)
to set direction of sort
URI examples:
/api/clients?start=21&limit=10
- 10 clients, starting from 21/api/places?sort_by=asc(zone),nr
- places sorted byzone
and then bynr