initial commit
This commit is contained in:
commit
ec90b19cf2
69
README.md
Normal file
69
README.md
Normal file
@ -0,0 +1,69 @@
|
||||
# FastAPI Project
|
||||
|
||||
This is a simple FastAPI project that includes two endpoints: one for user registration and another for user sign-up.
|
||||
|
||||
## Project Structure
|
||||
|
||||
```
|
||||
fastapi-project
|
||||
├── app
|
||||
│ ├── main.py
|
||||
│ ├── api
|
||||
│ │ ├── __init__.py
|
||||
│ │ └── endpoints
|
||||
│ │ ├── register.py
|
||||
│ │ └── signup.py
|
||||
│ └── models
|
||||
│ └── __init__.py
|
||||
├── requirements.txt
|
||||
└── README.md
|
||||
```
|
||||
|
||||
## Setup Instructions
|
||||
|
||||
1. Clone the repository:
|
||||
```
|
||||
git clone <repository-url>
|
||||
cd fastapi-project
|
||||
```
|
||||
|
||||
2. Create a virtual environment:
|
||||
```
|
||||
python -m venv venv
|
||||
```
|
||||
|
||||
3. Activate the virtual environment:
|
||||
- On Windows:
|
||||
```
|
||||
venv\Scripts\activate
|
||||
```
|
||||
- On macOS/Linux:
|
||||
```
|
||||
source venv/bin/activate
|
||||
```
|
||||
|
||||
4. Install the required dependencies:
|
||||
```
|
||||
pip install -r requirements.txt
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
To run the FastAPI application, execute the following command:
|
||||
```
|
||||
uvicorn app.main:app --reload
|
||||
```
|
||||
|
||||
You can access the API documentation at `http://127.0.0.1:8000/docs`.
|
||||
|
||||
## Endpoints
|
||||
|
||||
- **Register Endpoint**:
|
||||
- URL: `/register`
|
||||
- Method: `POST`
|
||||
- Description: Handles user registration.
|
||||
|
||||
- **Sign Up Endpoint**:
|
||||
- URL: `/signup`
|
||||
- Method: `POST`
|
||||
- Description: Handles user sign-up.
|
0
app/api/__init__.py
Normal file
0
app/api/__init__.py
Normal file
14
app/api/endpoints/register.py
Normal file
14
app/api/endpoints/register.py
Normal file
@ -0,0 +1,14 @@
|
||||
from fastapi import APIRouter, HTTPException
|
||||
from pydantic import BaseModel
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
class UserRegistration(BaseModel):
|
||||
username: str
|
||||
password: str
|
||||
email: str
|
||||
|
||||
@router.post("/register")
|
||||
async def register(user: UserRegistration):
|
||||
|
||||
return {"message": "User registered successfully", "user": user.username}
|
8
app/api/endpoints/signin.py
Normal file
8
app/api/endpoints/signin.py
Normal file
@ -0,0 +1,8 @@
|
||||
from fastapi import APIRouter
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
@router.post("/")
|
||||
async def sign_in_user(username: str, password: str):
|
||||
|
||||
return {"message": "User signed in successfully", "username": username}
|
15
app/main.py
Normal file
15
app/main.py
Normal file
@ -0,0 +1,15 @@
|
||||
from fastapi import FastAPI
|
||||
from app.api.endpoints import register, signin
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
app.include_router(register.router, prefix="/register", tags=["register"])
|
||||
app.include_router(signin.router, prefix="/signin", tags=["signin"])
|
||||
|
||||
@app.get("/")
|
||||
def read_root():
|
||||
return {"message": "Welcome to the FastAPI application!"}
|
||||
|
||||
if __name__ == "__main__":
|
||||
import uvicorn
|
||||
uvicorn.run("app.main:app", host="127.0.0.1", port=8000, reload=True)
|
0
app/models/__init__.py
Normal file
0
app/models/__init__.py
Normal file
3
requirements.txt
Normal file
3
requirements.txt
Normal file
@ -0,0 +1,3 @@
|
||||
FastAPI
|
||||
uvicorn
|
||||
pydantic
|
Loading…
x
Reference in New Issue
Block a user