Project Description : Create a RESTful API using FastAPI and SQLAlchemy to manage a simple database of users.
- Setup a new Python project with FastAPI and SQLAlchemy.
- Define a User model with fields for
id
,name
,email
, andpassword
. Create the corresponding SQLAlchemy table. - Implement CRUD operations for managing users:
- Create a new user.
- Retrieve a user by ID.
- Update a user's information.
- Delete a user.
- Create a FastAPI router to handle the API endpoints for user management.
- Implement input validation for user input and handle errors gracefully with appropriate status codes and error messages.
- Start the FastAPI application and test the endpoints using tools like
curl
orPostman
.
Project Description : 使⽤ FastAPI 和 SQLAlchemy 創建⼀個簡單的使⽤者資料庫管理 RESTful API。
- 設置⼀個新的 Python 專案,包含 FastAPI 和 SQLAlchemy。
- 定義⼀個使⽤者模型,包括
id
、name
、email
和password
欄位。建立對應的 SQLAlchemy 表格。 - 實現⽤於管理使⽤者的 CRUD 操作:
- 創建新使⽤者。
- 透過 ID 檢索使⽤者。
- 更新使⽤者資訊。
- 刪除使⽤者。
- 創建⼀個 FastAPI 路由器來處理使⽤者管理的 API 端點。
- 為使⽤者輸入實施輸入驗證,並使⽤適當的狀態碼和錯誤訊息優雅地處理錯誤。
- 啟動 FastAPI 應⽤程式,並使⽤
curl
或Postman
等⼯具測試端點。
Technical : Deploy the application on AWS EC2 using Nginx.
- Fast API Website:
http://13.238.194.179
- Fast API Document:
http://13.238.194.179/redoc
Statement : Get all user list from database
$ curl -X GET http://13.238.194.179/usermanagement
- 200 Successful Response
Statement : Create one user
$ curl.exe -X POST -H "Content-Type: application/json" -d '{"name": "Bill Gates", "email": "john@example.com", "password": "passwordA1"}' http://13.238.194.179/usermanagement
- name: required
- email: required
- password: required
- Name must contain a space
- Password length should be at least 8 characters
- Password should contain at least one digit
- Password should contain at least one uppercase letter
- Password should contain at least one lowercase letter
- Email should follow Email format
{
"email": "helloworld@gmail.com",
"name": "Bill Gates",
"password": "Th1sA3eCREtP3D#"
}
- 201 Successful Response
- 422 Validation Error
Statement : Get one user
$ curl http://13.238.194.179/usermanagement/{usermanagement_id}
- 200 Successful Response
- 422 Validation Error
Statement : Update name, email, password, by userid.
- name: required
- email: required
- password: required
$ curl -X PATCH -H "Content-Type: application/json" -d '{"name": "Bill Gates", "email": "helloworld@gmail.com", "password": "Th1sA3eCREtP3D#"}' http://13.238.194.179/usermanagement/{usermanagement_id}
{
"email": "helloworld@gmail.com",
"name": "Bill Gates",
"password": "Th1sA3eCREtP3D#"
}
- 200 Successful Response
- 422 Validation Error
Statement : Delete specific user by id. Replace usermanagement_id to the real usermangement_id
$ curl -X DELETE http://13.238.194.179/usermanagement/{usermanagement_id}
- 204 Successful Response
- 422 Validation Error