Blog API with DRF, Token Authentication, ReDoc Documentation
A complete Blog API project using Django REST Framework, with:
- Full CRUD operations for blogs
- Token-based authentication
- CKEditor integration for rich text
- ReDoc and Swagger API documentation
Project Setup
- Clone the repository
git clone https://github.com/babitabss/Blog-API-with-DRF.git cd assigenment 2.create virtual environment and install dependencies python -m venv myenv
myenv\Scripts\activate # Windows
3.apply migration python manage.py makemigrations python manage.py migrate 4.Collect static files (for CKEditor) python manage.py collectstatic 5.runserver python manage.py runserver Open your browser at http://127.0.0.1:8000/
ReDoc docs available at http://127.0.0.1:8000/redoc/
Swagger docs available at http://127.0.0.1:8000/swagger/
6.API Endpoints Method Endpoint Description GET /api/blogs/ List all blogs POST /api/blogs/ Create a blog GET /api/blogs// Retrieve a blog PUT /api/blogs// Update entire blog PATCH /api/blogs// Partial update DELETE /api/blogs// Delete a blog Authentication Method Endpoint Description POST /auth/login/ Login and get token POST /api/token/ JWT token obtain POST /api/token/refresh/ Refresh JWT token Test Credentials Username Password admin admin123 Notes
Only authenticated users can create, update, or delete blogs.
Anonymous users can only view published blogs.
All API responses follow a standardized format with status, message, and data.
This README is enough for anyone to clone your repo and run it.
If you want, I can make a fully polished, ready-to-copy README specifically for your Blog API project, including ReDoc links, CKEditor info, and sample requests/responses.
Do you want me to do that?
give the proper readme so that i can copy paste that
Absolutely! Here’s a fully polished README.md for your Blog API project using Django REST Framework. You can copy-paste it directly into your repo.
A complete Blog API project built with Django REST Framework (DRF), featuring:
- Full CRUD operations for blogs
- Token-based authentication (JWT)
- CKEditor integration for rich text blog content
- Interactive API documentation using ReDoc and Swagger
Project Setup
- Clone the repository
git clone https://github.com/babitabss/Blog-API-with-DRF.git
cd Blog-API-with-DRF
2. Create a virtual environment and install dependencies
python -m venv myenv
# Activate environment
# Windows
myenv\Scripts\activate
# Linux / Mac
source myenv/bin/activate
pip install -r requirements.txt
3. Set up environment variables
Create a .env file in the project root with the following content:
SECRET_KEY=your-secret-key
DEBUG=True
DATABASE_URL=sqlite:///db.sqlite3
4. Apply database migrations
python manage.py makemigrations
python manage.py migrate
5. Collect static files (required for CKEditor)
python manage.py collectstatic
Run the Project
python manage.py runserver
Open your browser at: http://127.0.0.1:8000/
ReDoc API docs: http://127.0.0.1:8000/redoc/
Swagger UI docs: http://127.0.0.1:8000/swagger/
API Endpoints
Blogs
Method Endpoint Description
GET /api/blogs/ List all blogs
POST /api/blogs/ Create a blog
GET /api/blogs/<id>/ Retrieve a blog
PUT /api/blogs/<id>/ Update entire blog
PATCH /api/blogs/<id>/ Partial update
DELETE /api/blogs/<id>/ Delete a blog
Authentication
Method Endpoint Description
POST /auth/login/ Login user (returns token)
POST /api/token/ Obtain JWT token
POST /api/token/refresh/ Refresh JWT token
Test Credentials
Username Password
admin admin123
You can use these credentials to test authenticated API operations.
Permissions & Rules
Only authenticated users can create, update, or delete blogs.
Only the blog author can update or delete their own blog.
Anonymous users can only view published blogs.
All API responses follow a standardized format:
Success Response:
{
"status": true,
"message": "Blog created successfully",
"data": {
"id": 1,
"title": "My First Blog",
"content": "<p>This is the content</p>",
"author": "john_doe",
"is_published": false,
"created_at": "2024-01-15T10:30:00Z"
}
}
Error Response:
{
"status": false,
"message": "Validation error",
"errors": {
"title": ["This field is required"]
}
}
API documentation is automatically generated and interactive via ReDoc and Swagger.
Use the Authorization header for endpoints requiring authentication:
Authorization: Token <your_token_here>
Ensure your virtual environment is active to avoid dependency issues.
T