Skip to content

Latest commit

 

History

History
188 lines (128 loc) · 3.65 KB

File metadata and controls

188 lines (128 loc) · 3.65 KB

API Reference

Base URL: http://localhost:3000

All routes are mounted under /api.


Users

Base path: /api/users

Register

Create a new user account.

Endpoint: POST /api/users/register

Required fields: firstName, lastName, email, password
Optional: avatar (file upload)

curl -X POST http://localhost:3000/api/users/register \
  -H "Content-Type: application/json" \
  -d '{
    "firstName": "John",
    "lastName": "Doe",
    "email": "john@example.com",
    "password": "123456"
  }'

With avatar (multipart):

curl -X POST http://localhost:3000/api/users/register \
  -F "firstName=John" \
  -F "lastName=Doe" \
  -F "email=john@example.com" \
  -F "password=123456" \
  -F "avatar=@/path/to/avatar.png"

Login

Authenticate a user and receive a JWT token.

Endpoint: POST /api/users/login

Required fields: email, password

curl -X POST http://localhost:3000/api/users/login \
  -H "Content-Type: application/json" \
  -d '{
    "email": "john@example.com",
    "password": "123456"
  }'

Get All Users

Returns a paginated list of users. Admin only.

Endpoint: GET /api/users

Query parameters:

Parameter Default Description
page 1 Page number
perPage 10 Items per page

Headers: Authorization: Bearer <token>

curl -X GET "http://localhost:3000/api/users?page=1&perPage=10" \
  -H "Authorization: Bearer YOUR_JWT_TOKEN"

Courses

Base path: /api/courses

Get All Courses

Returns a paginated list of courses.

Endpoint: GET /api/courses

Query parameters:

Parameter Default Description
page 1 Page number
perPage 1 Items per page
curl -X GET "http://localhost:3000/api/courses?page=1&perPage=10"

Get Course by ID

Endpoint: GET /api/courses/:courseId

curl -X GET http://localhost:3000/api/courses/COURSE_ID_HERE

Create Course

Endpoint: POST /api/courses

Required fields: name, price

curl -X POST http://localhost:3000/api/courses \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Node.js Basics",
    "price": 99
  }'

Update Course

Endpoint: PATCH /api/courses/:courseId

curl -X PATCH http://localhost:3000/api/courses/COURSE_ID_HERE \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Advanced Node.js",
    "price": 149
  }'

Delete Course

Endpoint: DELETE /api/courses/:courseId

curl -X DELETE http://localhost:3000/api/courses/COURSE_ID_HERE

Quick Test Flow

# 1. Register a user
curl -X POST http://localhost:3000/api/users/register \
  -H "Content-Type: application/json" \
  -d '{"firstName":"John","lastName":"Doe","email":"john@example.com","password":"123456"}'

# 2. Login and copy the token from the response
curl -X POST http://localhost:3000/api/users/login \
  -H "Content-Type: application/json" \
  -d '{"email":"john@example.com","password":"123456"}'

# 3. Create a course
curl -X POST http://localhost:3000/api/courses \
  -H "Content-Type: application/json" \
  -d '{"name":"Docker 101","price":50}'

Notes

  • Use /api/users/register, not /register.
  • Register requires firstName and lastName in addition to email and password.
  • GET /api/users requires an ADMIN role and a valid Authorization: Bearer <token> header.
  • Set JWT_SECRET_KEY in your environment (.env or Docker) for register and login to work.