# fastapi知识 **Repository Path**: trident_python/fastapi-knowledge ## Basic Information - **Project Name**: fastapi知识 - **Description**: fastapi知识 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-08-13 - **Last Updated**: 2026-09-26 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # FastAPI Knowledge Base Project This project is a simple web application example built on the FastAPI framework, demonstrating core FastAPI functionalities, including the use of path parameters, query parameters, and request bodies. ## Features - **Basic Routing**: Provides a root path `/` returning a welcome message - **Path Parameters**: Demonstrates the use of path parameters with validation rules - **Query Parameters**: Supports list query functionality with pagination and search - **Request Body**: User registration endpoint supporting data validation ## Quick Start ### Requirements - Python 3.7+ - FastAPI - Uvicorn (ASGI server) ### Install Dependencies ```bash pip install fastapi uvicorn ``` ### Start Service ```bash uvicorn main:app --reload ``` After the service starts, visit `http://127.0.0.1:8000` ## API Documentation After starting the service, you can access the interactive documentation via the following addresses: - Swagger UI: `http://127.0.0.1:8000/docs` - ReDoc: `http://127.0.0.1:8000/redoc` ## Endpoint Details ### 1. Root Path - **URL**: `GET /` - **Function**: Returns welcome message ### 2. Simple Path Parameter - **URL**: `GET /hi` - **Function**: Returns a simple greeting ### 3. Basic Path Parameter - **URL**: `GET /items/{item_id}` - **Function**: Get item by specified ID - **Parameter**: `item_id` (integer) ### 4. Validated User Path Parameter - **URL**: `GET /user/{uid}` - **Function**: Get information for specified user - **Parameter**: `uid` (integer, range 1-99) ### 5. Author Path Parameter - **URL**: `GET /author/{name}` - **Function**: Get information for specified author - **Parameter**: `name` (string, length 2-10) ### 6. News Category Path Parameter - **URL**: `GET /news_category/{cid}` - **Function**: Get specified news category - **Parameter**: `cid` (integer, range 2-99) ### 7. News List Query - **URL**: `GET /news/list` - **Function**: Paginated retrieval of news list - **Query Parameters**: - `name`: News title (optional, max length 40) - `page`: Page number (required, greater than 0) - `page_size`: Items per page (required, greater than 0) ### 8. User Registration - **URL**: `POST /user/register` - **Function**: Register new user - **Request Body**: User information (JSON format) ## Example Requests ### User Registration ```bash curl -X 'POST' \ 'http://127.0.0.1:8000/user/register' \ -H 'Content-Type: application/json' \ -d '{"username": "your_username", "password": "your_password"}' ``` ### Get User Information ```bash curl http://127.0.0.1:8000/user/25 ``` ### Query News List ```bash curl "http://127.0.0.1:8000/news/list?name=科技&page=1&page_size=10" ``` ## Project Structure ``` fastapi-knowledge/ ├── main.py # Main application code ├── test.txt # Test file └── README.md # Project documentation ``` ## License This project is for learning and communication purposes only.