✨Python WebAPI Dev✨ - JIANG
🖱️ Click below to navigate to the backend FastAPI page
📚 Tech Stack
- Python
- FastAPI (fastest API builder, Faster than Django and Flask)
- Sqlalchemy (SQL toolkit and relational mapper)
- Alembic (Database migration)
- Pydantic (Modeling, data typing)
- OAuth2 (Authentication with Bear token)
- Psycopg2 (Database driver)
- Jose (Authentication with JSON Web Signature)
- Passlib (SHA256 hash encryption for security)
- Uvicorn (Local web server for testing)
- PostgreSQL - free open-source relational database software
- PgAdmin4 - GUI for PostgreSQL
- Postman - API testing
- Heroku - Web server host
☘️ API Details
🏞️ Prerequisite
Firstly, create a user with Users ⇒ Post
/users/ create user (green button) ⇒ Try it out
=> Edit "email" and "password" strings => Execute
. In Server Response under the Responses section, if you see the 201 code with your account detail, congrats!
Secondly, log in with Authorize
(top right) button. You need to create a user first, following the instruction above.
Thirdly, you are now a freeman who can try some APIs.
🎆 Posts
- GET /posts/ - No specific authentication is needed. Expecting return of all created posts by all users
- POST /posts/ - Expecting: 201 Code, in the Server response section
- POST /posts/ - Expecting: 201 Code, in the Server response section. Both time and your id would automatically logged in the backend
- PUT /posts/{id} - Expecting: 200 Code, in the Server response section. Your new post title and content would be updated
- DELETE /posts/{id} - Expecting: 204 Code, in the Server response section. Your selected post would be deleted. Your login is required and you are only authorized to delete your own posts
💁♂️ Users
- POST /users/ - Expecting: 201 Code, in the Server response section. You will be assigned a user id
- GET /users/{id} - Expecting: 202 Code, in the Server response section. It will return your account information
🔐 Authentication
- POST /login - Expecting: 200 Code
👍 Vote
- POST /vote/ - Expecting: 200 Code with a success message.
post_id
is the post you want to vote on.dir
is the direction of the vote: 1 is upvote, -1 is downvote. If you voted for this post id before, you can’t repeatedly upvote. The same as a downvote
🍊 Default
- This route should you the current page of instructions and docs
🍹 Project Reflection
- I am familiar with Conda environment and VS Code. I tried something new. Venv and PyCharm make a great combination, if you mind the biggest memory hog - PyCharm.
- Pydantic ensures data model. It is especially important because API building is basically building a data pipeline that ensures the data transform into the right format.
- Data migration with scripting using Sqlalchemy and Alembic amazes me. Though I spent 1 whole day debugging Alembic version issue. However, it is worthy because it helps you implement all data schemes into a web server like Heroku very smoothly with the command
heroku run "alembic upgrade head"
.
- Create users, user login, user does CRUD operation on posts with authentication feature could be operated directly with
/docs
s or/redoc
is very convenient. You don’t need Postman and you can test in a smaller scale. But nothing beats Postman’s environment features (DEV, PROD, Variable for secret tokens).
⛓️ Links
- Github page
- Repository page: https://github.com/zjian107-su/Python-WebAPI-Dev
- LeetCode
- Syracuse University article about me
- Newspaper (The Daily Orange) article about me
- My other web projects