- Base code: Flask App + Swagger UI
- How to install & Run Cockroach Database
- How to install & Run RedisDB
- How to install & Run Elasticsearch
- Enable auth login and logout
- Enable connection with RedisDB for storing JWT information
- Integrate with CockroachDB, e.g., CRUD of
User Model
with CRDB- Sample
Create
new user - Sample
Read
user all - Sample
Read
user by username - Sample
Delete
user by username - Nested URL input parameters
- Combination with POST & GET parameters
- Simple migration (auto add new table model)
- Advanced migration (auto detect new update of the table pattern)
- Sample
- Integration with Elasticsearch
- Complete documentation
- Python Flask
- Swagger UI
- Redis Database
- Cockroach Database
- Python 3, https://www.python.org/download/releases/3.0/
- Python Flask Web Server, http://flask.pocoo.org
- Redis Key-Value Database, https://redis.io
-
Python library
pip install -r requirements.txt
-
Install Redis Database
- Install docker.io
- Install redis-tools
- Go to redis directory:
$ cd others/redis
- Install
Dockerfile
:$ docker build -t 5g-dive/redis:1.0 .
-
Install Coachroach Database: Click here
-
Configure CockroachDB:
- Follow step here and here
- Add new user:
- login:
$ cockroach sql --certs-dir=certs --host=localhost:26257
- Create new database:
CREATE DATABASE flaskapi;
- Create new user (Insecure Mode):
CREATE USER flaskuser;
- Grant user the database access:
GRANT ALL ON DATABASE flaskapi TO flaskuser;
- login:
-
Run RedisDB
- Go to directory "
others/redis
" :$ cd others/redis
- Instantiate redis container:
$ . run.sh
- Test inserting data into RedisDB:
$ . test.sh
- Go to directory "
-
Run CoachroachDB
- Instantiate Database server:
$ cockroach start --insecure --listen-addr=localhost
- Login SQL:
$ cockroach sql --insecure
- Instantiate Database server:
-
Run Flask Web Service
- Run flask web server:
$ flask run
- Run flask web server:
RedisDB used only to store JWT-related information
- AUTH
POST /api/auth/login
GET /api/auth/logout
GET /api/refresh
- USER
POST /api/users
GET /api/users
DELETE /api/users
GET /api/users/username/<username>
DELETE /api/users/username/<username>
GET /api/users/hobby/register_between/<start_date>/<end_date>
GET /api/users/<hobby>/<register_after>
GET /api/users/<user_id>
PUT /api/users/<user_id>
DELETE /api/users/<user_id>
{
"status" : bool,
"message" : string,
"results" : `LIST` or `DICT`
}
This Web Service returns the following status codes in its API:
Status Code | Description |
---|---|
200 | OK |
400 | BAD REQUEST |
401 | Unauthorized Access. Access Token should be provided and validated. |
403 | FORBIDDEN |
404 | NOT FOUND |
500 | INTERNAL SERVER ERROR |
Self-Maintained. If there any issue, please do not hesitate to contact me.
- Muhammad Febrian Ardiansyah, https://github.com/ardihikaru
- Thread with
concurrent.futures
; https://docs.python.org/3/library/concurrent.futures.html#concurrent.futures.ThreadPoolExecutor - Flask Restplus in HTTPS ; https://stackoverflow.com/questions/47508257/serving-flask-restplus-on-https-server
- Monkey patch : noirbizarre/flask-restplus#54