This documentation describes the API endpoints for user registration, login, health information management, and logout functionality in the Django REST Framework (DRF) application. The endpoints are primarily focused on managing user accounts and health-related data for patients and healthcare practitioners.
Link to the frontend repo: https://github.com/moloruntomiwa31/mobi-maternity-frontend
Link to the website: https://mobi-maternity-frontend.vercel.app
- Base URL:
/api/
-
User Registration
POST /api/user-create/
-
User Detail
GET /api/user-detail/
-
Health Information Registration
PUT /api/health-info/create/
-
Health Information Detail
GET /api/health-info/
-
HealthWorker Info Registration
PUT /api/health-worker/create/
-
HealthWorker Information Detail
GET /api/health-worker/
-
Login
POST /api/login/
-
Logout
POST /api/logout/
- URL:
/api/user-create/
- Method:
POST
- Authentication: None (Open to all)
- Description: Registers a new user (patient or healthcare practitioner).
- Request Body:
{ "username": "string", "password": "string", "first_name": "string", "last_name": "string", "phone_number": "string", "date_of_birth": "YYYY-MM-DD", "gender": "M/F", "role": "P/H" }
- Response:
- 201 Created
{ "username": "string", "first_name": "string", "last_name": "string", "phone_number": "string", "date_of_birth": "YYYY-MM-DD", "gender": "M/F", "role": "P/H" }
- URL:
/api/user-detail/
- Method:
GET
- Authentication: Basic Authentication
- Permission: Authenticated users only
- Description: Retrieves details of the logged-in user.
- Response:
- 200 OK
{ "username": "string", "first_name": "string", "last_name": "string", "phone_number": "string", "date_of_birth": "YYYY-MM-DD", "gender": "M/F", "role": "P/H" }
- URL:
/api/health-info/create/
- Method:
PUT
- Authentication: Basic Authentication
- Permission: Authenticated users with the role
P
(Patient) - Description: Allows patients to create or update their health information.
- Request Body:
{ "pregnancy_status": "true/false", "due_date": "YYYY-MM-DD", "health_conditions": "string" }
- Response:
- 200 OK (If health info updated)
{ "message": "Health information updated successfully" }
- 201 Created (If health info created)
{ "message": "Health information created successfully" }
- URL:
/api/health-info/
- Method:
GET
- Authentication: Basic Authentication
- Permission: Authenticated users with the role
P
(Patient) - Description: Retrieves the health information of the logged-in patient.
- Response:
- 200 OK
{ "pregnancy_status": "true/false", "due_date": "YYYY-MM-DD", "health_conditions": "string" }
Endpoint: /health-worker/create/
Method: PUT
Description: Create or update health worker information. Only accessible by users with the role H.
Permission: IsAuthenticated
Request Headers:
Authorization: Basic <credentials>
Request Body:
json
{
"medical_license_number": "string",
"specialty": "string",
"clinic_location": "string",
"hospital_name": "string"
}
Response:
200 OK: Health worker information created or updated successfully.
403 Forbidden: The user is not a healthcare worker.
401 Unauthorized: Authentication required.
Endpoint: /health-worker/
Method: GET
Description: Retrieve health worker information for the authenticated healthcare worker.
Permission: IsAuthenticated
Request Headers:
Authorization: Basic <credentials>
Response:
200 OK: Health worker information retrieved successfully.
403 Forbidden: The user is not a healthcare worker.
401 Unauthorized: Authentication required.
- URL:
/api/login/
- Method:
POST
- Authentication: None (Open to all)
- Description: Authenticates a user and returns a success message upon successful login.
- Request Body:
{ "username": "string", "password": "string" }
- Response:
- 200 OK
{ "message": "Login successful", "data": { "username": "string", "password": "string" } }
- 401 Unauthorized
{ "error": "Invalid credentials" }
- URL:
/api/logout/
- Method:
POST
- Authentication: Basic Authentication
- Permission: Authenticated users only
- Description: Logs out the authenticated user and deletes their token/Session.
- Response:
- 200 OK
{ "message": "Logout successful" }
- 400 Bad Request
{ "error": "Error message" }
- Role-based access control: Patients can access and manage their health records, while healthcare practitioners are restricted from accessing or modifying patient-specific health information.
- Authentication: Basic Authentication is enforced for all endpoints except user registration and login, ensuring that only authenticated users can access their data.
- Security: Ensure that HTTPS is used in production to encrypt sensitive data transmitted between the client and the server.