Skip to content

dushyantss8/Python-FastAPI-Reference

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

FastAPI CRUD Example

This is a simple FastAPI application that demonstrates basic CRUD operations for blog posts using in-memory storage (a Python list). It does not use any views or templates β€” purely an API backend.

πŸ“ Project Structure

.
β”œβ”€β”€ main.py         # The main FastAPI application
β”œβ”€β”€ README.md       # Project documentation
└── .gitignore      # Ignored files and folders

πŸš€ Features

  • 🟒 Get all posts
  • 🟑 Create a new post
  • πŸ”΅ Get a single post by ID
  • πŸ”΄ Delete a post by ID

πŸ”§ Requirements

  • Python 3.7+
  • FastAPI
  • Uvicorn

Install dependencies:

pip install fastapi uvicorn

▢️ Running the Application

Use uvicorn to run the FastAPI app:

uvicorn main:app --reload
  • --reload: enables hot-reload on code changes (useful for development)

🌐 API Endpoints

Method Endpoint Description
GET / Root message
GET /posts Retrieve all posts
POST /posts Create a new post
GET /posts/{id} Retrieve a post by ID
DELETE /posts/{id} Delete a post by ID

Example POST Body

{
  "title": "Sample Title",
  "content": "Sample content goes here",
  "published": true,
  "rating": 5
}

πŸ“¦ Notes

  • The application uses in-memory storage (my_posts list), so data resets every time the server restarts.
  • ID is randomly generated using Python's randrange.

πŸ“š Learn More


Happy coding! 🐍

About

A beginner-friendly reference project built using FastAPI and Python.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages