A FastAPI-based RESTful API for creating, managing, and fetching blog posts and users. This project includes authentication, database management using SQLAlchemy, and JWT token-based security.
- Python: Core programming language used for backend logic and application structure.
- FastAPI: A modern, fast web framework used for building APIs with Python.
- SQLAlchemy: SQL toolkit and Object-Relational Mapping (ORM) library for database management.
- SQLite: Lightweight relational database used to store data.
- OAuth2 (with JWT Token): Authentication framework for handling secure user logins.
- Pydantic: Data validation and settings management using Python type hints.
- bcrypt: For securely hashing and verifying user passwords.
- Passlib: Library for secure password hashing and verification.
- Uvicorn: ASGI server for running FastAPI apps.
- Swagger UI and Postman: For testing and validating API requests and responses.
- This project provides a backend API built using FastAPI.
- The API allows users to perform CRUD operations on blog posts and user data, with JWT authentication to secure access.
- SQLAlchemy is used for database management with SQLite as the backend.
- Blog Management: Users can create, read, update, and delete blog posts.
- User Management: Create and fetch user data.
- JWT Authentication: Secure endpoints using JWT tokens for login and authentication.
- SQLAlchemy ORM: Database operations are handled through the ORM.
- Password Hashing: User passwords are stored securely with bcrypt hashing.
- Dynamic Routing: Fetch and manage resources dynamically using route parameters.
- Clone the repository:
https://github.com/Abhimanyu-Gaurav/Learn_fastapi
- Navigate to the project directory:
cd Learn_fastapi
- Set up a virtual environment (optional but recommended):
python -m venv venv source venv/bin/activate # On Windows use `venv\Scripts\activate`
- Install the required dependencies:
pip install -r requirements.txt
- Run the FastAPI server:
uvicorn main:app --reload
- API will be running at:
http://127.0.0.1:8000/
- Open your browser (Safari, Chrome, Brave) and enter the URL:
http://localhost:8000/docs#
- API Endpoints:(view this in Swagger UI)
- GET /: Returns a welcome message.
- GET /about: Returns basic information about the API.
- GET /blog: Fetches published or unpublished blogs.
- POST /blog: Creates a new blog post.
- GET /blog/{id}: Fetches details of a specific blog post by its ID.
- GET /user: Fetches user details.
- POST /login: Logs in a user and returns a JWT token for authentication.
- Authentication: Secure endpoints require a JWT token. To authenticate, log in using /login and pass the token in the Authorization header for subsequent requests:
-
Using Postman:
- Open Postman and click the "New" button to create a new request.
- Set the request type to GET/POST/DELETE/PUT from the dropdown menu next to the URL field.
- Set for check , whatever is in API endpoints.
-
Using cURL:
- we can perform it using cURL also.
- This project is licensed under the MIT License - see the License file for details.