Simplest api ever created with CRUD and token authentication
- Documentation
- Features
- Getting Started
- Running the tests
- Deployment
- Built With
- Contributing
- Versioning
- Authors
- License
- Acknowledgments
- CRUD operations
- User authentication
- Tokens
- Limitation for api requests (default:300 requests per minute)
- Upload files on server with Flask-Upload extension implemented
SimpleApi is Flask application developed for fast development of simple APIs,this package uses SQLite3 as default database and SQLAlchemy to comunitcate with database.
For running this package you will need few other packages
pip install Redis
pip install Flask
pip install SQLAlchemy
pip install Flask-HTTPAuth
- Redis package is for limation on requests
- Flask package is micro-framework itself
- SQLAlchemy package is for communication with SQLite3 database
- Flask-HTTPAuth package is for authentication users and restricting routes with login required
SimpleApi is easy to setup you just need to clone or download directory and run it as shown bellow
git clone https://github.com/phpwizz/SimpleApi.git
cd /dir/SimpleApi/
python views.py
And that is it ! Now you have your own api on localhost:8080/api/v1/
To generate token in SimpleApi you will first need to be logged in , for that you will first need to create account in
http://localhost:8080/user/auth/token
Output:
{
"token" : "eyJhbGciOiJIUzI1NiI eyJhbGciOiJIUzI1NiIsImV4cCI6MTUzMTMxNzYxMSwiaWF0IjoxNTMxMzE3MDExfQ.eyJpZCI6MX0.N6KGiEivg3aZCWlkUPjNLNfphUmZx5ssXW56KoPakK0"
}
This token has expiration date of 600 minutes by default but that can be extended on more if is needed.
Open any REST api client this tutorial will cover use of Advanced REST client
-
Open a client application
-
For methode chose GET
This will show JSON format for all users
For url put : http://localhost:8080/api/v1/users
Output:
{
"Users": [
{
"id": 1,
"name": "Alex",
"picture": "https://thumbs.dreamstime.com/b/profile-icon-male-avatar-portrait-casual-person-silhouette-face-flat-design-vector-47075236.jpg",
"user_about": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. ",
"username": "alex123"
},
{
"id": 2,
"name": "Mark",
"picture": null,
"user_about": null,
"username": "marY2"
}
]
}
-
Open a client application
-
For methode chose POST
POST method in this package is used for creating new database entries ex.register new user or creating a new post
Creating new user
For url put : http://localhost:8080/api/v1/user/register/new
Set headers to Content-Type and application/json
Input:
{
"username": "test12",
"password": "test2"
}
Output:
{
"Created": "test12"
}
Application will respond with success message!
If you are familier with curl command you can do it this way
curl -i -X POST -H 'Content-Type: application/json' -d '{"username":"1","password":"1"}' http://localhost:8080/api/v1/user/register/new
Info : For this step you need to have already registered user
-
Open a client application
-
For methode chose PUT
PUT method in this package is used for updatung already existent database entries ex.change user name , change content for post
Updating user username
For url put : http://localhost:8080/api/v1/user/id/1/edit/username
Set headers to Content-Type and application/json
Input:
{
"username": "changedusername"
}
Output:
{
"username": "changedusername"
}
Application will respond with new value added for username!
-
Open a client application
-
For methode chose DELETE
DELETE method in this package is used for removing ex.users or posts
Removing user with specific id
- For url put : http://localhost:8080/api/v1/user/id/1/delete
Set headers to Content-Type and application/json
Output:
{
"Deleted": "Success"
}
Application will respond with success message!
Info: Same process can be applied for managing with posts!
Tutorial for deploying any flask application on heroku
- Flask - The micro-framework used
- SQLAlchemy - Database communicator
- Redis - Used to set limitations on requests
Everyone is welcome to contribute to this project.
- Version : v1.0
- phpwizz - phpwizz
On this link will be set all future contributors. The best contributers will be added as co-authors
This project is licensed under the MIT License - see the LICENSE.md file for details
- Flask official documantion
- Udacity course for APIs
- Logo icon: