A Django REST API for managing weekly schedules with time slots and associated IDs.
- CRUD operations for time slots
- JWT Authentication
- Swagger documentation
- Weekly schedule endpoint
- Clone the repository
- Install dependencies:
pip install -r requirements.txt - Run migrations:
python manage.py makemigrations python manage.py migrate - Create a superuser:
python manage.py createsuperuser - Run the server:
python manage.py runserver
/api/timeslots/- CRUD operations for time slots/api/schedule/- Get the complete weekly schedule/api/token/- Get JWT token/api/token/refresh/- Refresh JWT token/swagger/- Swagger UI/redoc/- ReDoc UI
This project uses djangorestframework-simplejwt for JWT authentication. Here's how it's implemented:
-
Install the package:
pip install djangorestframework-simplejwt -
Add to INSTALLED_APPS in settings.py:
INSTALLED_APPS = [ # ... 'rest_framework', 'rest_framework_simplejwt', ]
-
Configure REST framework to use JWT authentication:
REST_FRAMEWORK = { 'DEFAULT_AUTHENTICATION_CLASSES': [ 'rest_framework_simplejwt.authentication.JWTAuthentication', ], }
-
Add JWT URLs to urls.py:
from rest_framework_simplejwt.views import TokenObtainPairView, TokenRefreshView urlpatterns = [ # ... path('api/token/', TokenObtainPairView.as_view(), name='token_obtain_pair'), path('api/token/refresh/', TokenRefreshView.as_view(), name='token_refresh'), ]
-
To use JWT authentication:
- Get a token by sending a POST request to
/api/token/with username and password - Include the token in the Authorization header of your requests:
Authorization: Bearer <your_token> - Refresh the token by sending a POST request to
/api/token/refresh/with the refresh token
- Get a token by sending a POST request to
curl -X POST "http://localhost:8000/api/token/" -H "Content-Type: application/json" -d '{"username":"your_username","password":"your_password"}'curl -X POST "http://localhost:8000/api/timeslots/" -H "Authorization: Bearer <your_token>" -H "Content-Type: application/json" -d '{"day_of_week":"monday","start":"09:00","stop":"11:00","ids":[1,2,3]}'curl -X GET "http://localhost:8000/api/schedule/" -H "Authorization: Bearer <your_token>"