commit ec90b19cf219ae17a156d6b6c1f3000a69e47269 Author: lamido Date: Thu Mar 6 00:35:32 2025 +0100 initial commit diff --git a/README.md b/README.md new file mode 100644 index 0000000..8063f63 --- /dev/null +++ b/README.md @@ -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 + 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. \ No newline at end of file diff --git a/app/api/__init__.py b/app/api/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/app/api/endpoints/register.py b/app/api/endpoints/register.py new file mode 100644 index 0000000..dfd4201 --- /dev/null +++ b/app/api/endpoints/register.py @@ -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} \ No newline at end of file diff --git a/app/api/endpoints/signin.py b/app/api/endpoints/signin.py new file mode 100644 index 0000000..1cd3810 --- /dev/null +++ b/app/api/endpoints/signin.py @@ -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} \ No newline at end of file diff --git a/app/main.py b/app/main.py new file mode 100644 index 0000000..6902cd1 --- /dev/null +++ b/app/main.py @@ -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) \ No newline at end of file diff --git a/app/models/__init__.py b/app/models/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..8cf147b --- /dev/null +++ b/requirements.txt @@ -0,0 +1,3 @@ +FastAPI +uvicorn +pydantic \ No newline at end of file