A simple RESTful API built with Django REST Framework for managing a book collection. This project demonstrates basic CRUD operations and REST API concepts.
- Full CRUD functionality for books
- RESTful API endpoints
- JSON data format
- Built with Django REST Framework
- Python 3.8+
- Django 4.0+
- Django REST Framework
- Clone the repository
git clone https://github.com/Shreyescodes/django-book-api.git
cd django-book-api
- Create and activate virtual environment
python -m venv venv
source venv/bin/activate # On Windows use: venv\Scripts\activate
- Install dependencies
pip install django djangorestframework
- Run migrations
python manage.py makemigrations
python manage.py migrate
- Start the development server
python manage.py runserver
Method | Endpoint | Description |
---|---|---|
GET | /api/books/ |
List all books |
POST | /api/books/ |
Create a new book |
GET | /api/books/{id}/ |
Retrieve a book |
PUT | /api/books/{id}/ |
Update a book |
DELETE | /api/books/{id}/ |
Delete a book |
Creating a new book:
curl -X POST http://localhost:8000/api/books/ \
-H "Content-Type: application/json" \
-d '{
"title": "Django for Beginners",
"author": "John Doe",
"description": "A comprehensive guide to Django",
"price": "29.99"
}'
bookstore/
├── books/
│ ├── models.py # Book model
│ ├── serializers.py # Book serializer
│ └── views.py # BookViewSet
├── bookstore/
│ ├── settings.py # Project settings
│ └── urls.py # URL configurations
└── manage.py
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature
) - Commit your changes (
git commit -m 'Add some AmazingFeature'
) - Push to the branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.