A simple Django REST API for managing books using Django REST Framework.
- CRUD operations for books
- RESTful API endpoints
- Django Admin interface
- SQLite database (default)
- Python 3.8+
- Django 5.2.6
- Django REST Framework 3.16.1
git clone https://github.com/4urie/API-Programming-Exercise
cd API
# Windows
python -m venv myenv
myenv\Scripts\activate
# macOS/Linux
python3 -m venv myenv
source myenv/bin/activate
pip install django==5.2.6
pip install djangorestframework==3.16.1
cd myproject
python manage.py makemigrations
python manage.py migrate
python manage.py createsuperuser
python manage.py runserver
The API will be available at http://127.0.0.1:8000/
- GET
/api/books/
- List all books - POST
/api/books/
- Create a new book - GET
/api/books/{id}/
- Retrieve a specific book - PUT
/api/books/{id}/
- Update a specific book - PATCH
/api/books/{id}/
- Partially update a specific book - DELETE
/api/books/{id}/
- Delete a specific book
id
- Auto-generated primary keytitle
- Book title (max 200 characters)author
- Book author (max 200 characters)published_date
- Publication date
curl -X POST http://127.0.0.1:8000/api/books/ \
-H "Content-Type: application/json" \
-d '{
"title": "The Great Gatsby",
"author": "F. Scott Fitzgerald",
"published_date": "1925-04-10"
}'
curl -X GET http://127.0.0.1:8000/api/books/
curl -X GET http://127.0.0.1:8000/api/books/1/
curl -X PUT http://127.0.0.1:8000/api/books/1/ \
-H "Content-Type: application/json" \
-d '{
"title": "The Great Gatsby - Updated",
"author": "F. Scott Fitzgerald",
"published_date": "1925-04-10"
}'
curl -X DELETE http://127.0.0.1:8000/api/books/1/
Access the Django admin interface at http://127.0.0.1:8000/admin/
using the superuser credentials you created.
myproject/
├── api/
│ ├── migrations/
│ ├── __init__.py
│ ├── admin.py
│ ├── apps.py
│ ├── models.py
│ ├── serializers.py
│ ├── tests.py
│ ├── urls.py
│ └── views.py
├── myproject/
│ ├── __init__.py
│ ├── asgi.py
│ ├── settings.py
│ ├── urls.py
│ └── wsgi.py
├── db.sqlite3
├── manage.py
└── README.md
python manage.py test
- Make your changes to the code
- Create and apply migrations if you modify models:
python manage.py makemigrations python manage.py migrate
- Test your changes
- Commit and push to GitHub
- Fork the repository
- Create a feature branch
- Make your changes
- Submit a pull request
This project is open source and available under the MIT License.
- GitHub: @4urie
- Email: nellas.aurie@dnsc.edu.ph