Skip to content

Latest commit

 

History

History
185 lines (150 loc) · 4.07 KB

File metadata and controls

185 lines (150 loc) · 4.07 KB

API Endpoints Documentation

Base URL

http://localhost:3000

Available Endpoints

1. Health Check

  • GET /api/v1/health - Kiểm tra trạng thái ứng dụng

2. Authentication

  • POST /api/v1/auth/register - Đăng ký tài khoản mới
  • POST /api/v1/auth/login - Đăng nhập
  • POST /api/v1/auth/google - Đăng nhập với Google
  • POST /api/v1/auth/refresh - Làm mới token
  • GET /api/v1/auth/me - Lấy thông tin user hiện tại
  • POST /api/v1/auth/logout - Đăng xuất

3. Users

  • GET /api/v1/users - Lấy danh sách tất cả users
  • GET /api/v1/users/:id - Lấy thông tin user theo ID
  • POST /api/v1/users - Tạo user mới
  • PUT /api/v1/users/:id - Cập nhật thông tin user
  • DELETE /api/v1/users/:id - Xóa user

⚠️ Yêu cầu: JWT Bearer Token với role ADMIN

4. Projects

  • GET /api/v1/projects - Lấy danh sách projects của user hiện tại
  • POST /api/v1/projects - Tạo project mới
  • GET /api/v1/projects/:id - Lấy thông tin chi tiết project
  • DELETE /api/v1/projects/:id - Xóa project

⚠️ Yêu cầu: JWT Bearer Token (chỉ owner mới có quyền truy cập)

5. Resources

  • GET /api/v1/projects/:projectId/resources/check-name?name=xxx - Kiểm tra tên resource có sẵn trong project
  • POST /api/v1/projects/:projectId/resources - Tạo resource mới trong project
  • GET /api/v1/projects/:projectId/resources - Lấy danh sách resources của project
  • GET /api/v1/resources/:resourceId - Lấy chi tiết resource
  • DELETE /api/v1/resources/:resourceId - Xóa resource

⚠️ Yêu cầu: JWT Bearer Token (chỉ owner của project mới có quyền truy cập)

Request/Response Examples

Register User

POST /api/v1/auth/register
Content-Type: application/json

{
  "email": "user@example.com",
  "password": "password123",
  "name": "John Doe"
}

Login

POST /api/v1/auth/login
Content-Type: application/json

{
  "email": "user@example.com",
  "password": "password123"
}

Get Current User Profile

GET /api/v1/auth/me
Authorization: Bearer YOUR_ACCESS_TOKEN

Refresh Token

POST /api/v1/auth/refresh
Content-Type: application/json

{
  "refreshToken": "YOUR_REFRESH_TOKEN"
}

Logout

POST /api/v1/auth/logout
Authorization: Bearer YOUR_ACCESS_TOKEN

Create User

POST /api/v1/users
Content-Type: application/json
Authorization: Bearer YOUR_ACCESS_TOKEN

{
  "email": "newuser@example.com",
  "name": "New User"
}

Create Project

POST /api/v1/projects
Content-Type: application/json
Authorization: Bearer YOUR_ACCESS_TOKEN

{
  "name": "My New Project"
}

Get All Projects

GET /api/v1/projects
Authorization: Bearer YOUR_ACCESS_TOKEN

Get Project Detail

GET /api/v1/projects/:id
Authorization: Bearer YOUR_ACCESS_TOKEN

Delete Project

DELETE /api/v1/projects/:id
Authorization: Bearer YOUR_ACCESS_TOKEN

Check Resource Name Availability

GET /api/v1/projects/:projectId/resources/check-name?name=users
Authorization: Bearer YOUR_ACCESS_TOKEN

Response khi available:

{
  "available": true
}

Response khi không available:

{
  "available": false,
  "message": "Resource name \"users\" already exists in this project"
}

Create Resource

POST /api/v1/projects/:projectId/resources
Content-Type: application/json
Authorization: Bearer YOUR_ACCESS_TOKEN

{
  "name": "users"
}

Note: Name phải tuân theo format chuẩn API endpoint (lowercase, alphanumeric + hyphens/underscores). Name phải unique trong project. Nếu trùng sẽ nhận lỗi 409 Conflict.

Get All Resources

GET /api/v1/projects/:projectId/resources
Authorization: Bearer YOUR_ACCESS_TOKEN

Get Resource Detail

GET /api/v1/resources/:resourceId
Authorization: Bearer YOUR_ACCESS_TOKEN

Delete Resource

DELETE /api/v1/resources/:resourceId
Authorization: Bearer YOUR_ACCESS_TOKEN