Skip to content
Chris Dedman-Rollet edited this page Nov 11, 2024 · 2 revisions

API Documentation

This API documentation provides detailed information for our endpoint. Each section outlines the HTTP method, endpoint, a description of the operation, and the required request body. It also includes example curl commands to demonstrate how to interact with the API (or just use Postman).

Registration API

  • Endpoint: POST /register
  • Description: Registers a new user (select a role between Student and Educator)
  • Request Body:
    {
        "username": "dev",
        "email": "[email protected]",
        "password": "MyPasssword123",
        "confirm_password": "MyPasssword123",
        "role": "student"
    }
  • Example:
    curl -X POST http://localhost:4000/register -H "Content-Type: application/json" -d '{
        "username": "dev",
        "email": "[email protected]",
        "password": "MyPasssword123",
        "confirm_password": "MyPasssword123",
        "role": "student"
    }'

Login API

  • Endpoint: POST /login
  • Description: Logs in an existing user.
  • Request Body:
    {
        "email": "[email protected]",
        "password": "MyPasssword123"
    }
  • Example:
    curl -X POST http://localhost:4000/login -H "Content-Type: application/json" -d '{
        "email": "[email protected]",
        "password": "MyPasssword123"
    }'

Delete API

  • Endpoint: DELETE /delete
  • Description: Deletes a user by user_id.
  • Request Body:
    {
        "password": "Password1234",
        "user_id": "1"
    }
  • Example:
    curl -X DELETE http://localhost:4000/delete -H "Content-Type: application/json" -d '{
        "password": "Password1234",
        "user_id": "1"
    }'

User API

  • Endpoint: GET /user/:user_id
  • Description: Get user by user_id.
  • Example:
    curl -X GET http://localhost:4000/user/10

Update Username API

  • Endpoint: PUT /update-username

  • Description: Updates the username of a user.

  • Request Body:

    {
        "user_id": "1",
        "token": "your_token_here",
        "username": "newUsername"
    }
  • Example:

    curl -X PUT http://localhost:4000/update-username -H "Content-Type: application/json" -d '{
        "user_id": "1",
        "token": "your_token_here",
        "username": "newUsername"
    }'

Update Email API

  • Endpoint: PUT /update-email

  • Description: Updates the email address of a user. For validation, the confirm_email field must match the email field.

  • Request Body:

    {
        "user_id": "1",
        "token": "your_token_here",
        "email": "[email protected]",
        "confirm_email": "[email protected]"
    }
  • Example:

    curl -X PUT http://localhost:4000/update-email -H "Content-Type: application/json" -d '{
        "user_id": "1",
        "token": "your_token_here",
        "email": "[email protected]",
        "confirm_email": "[email protected]"
    }'

Update Password API

  • Endpoint: PUT /update-password

  • Description: Updates the user's password and logs the user out by revoking the current token. The confirm_password field must match the password field, and a valid token is required for authentication.

  • Request Body:

    {
        "user_id": "1",
        "token": "your_token_here",
        "password": "NewPassword123",
        "confirm_password": "NewPassword123"
    }
  • Example:

    curl -X PUT http://localhost:4000/update-password -H "Content-Type: application/json" -d '{
        "user_id": "1",
        "token": "your_token_here",
        "password": "NewPassword123",
        "confirm_password": "NewPassword123"
    }'
Clone this wiki locally