# REST Resource Naming Guide - Bài viết được dịch và tham khảo từ trang https://restfulapi.net/resource-naming/ ## Một số quy tắc chung - Lấy ra danh sách entities, ta viết: ``` /api/entities ``` - Lấy ra một entity cụ thể theo id, ta viết ``` /api/entities/{entityId} ``` - Truy cập một danh sách mà entity đó chứa: ``` /api/entities/{entityId}/collection ``` - Tương tự, lấy ra 1 collection item thuộc entity cho trước: ``` /api/entities/{entityId}/collection/{collectionItemId} ``` - Không dùng kí hiệu '_' (underscore) để phân tách word ``` /inventory-management/managed-entities/{id}/install_script_location <-- Bad /inventory-management/managed-entities/{id}/installScriptLocation <-- Bad /inventory-management/managed-entities/{id}/install-script-location <-- Good ``` - Dùng lowercase letter ``` http://api.example.org/my-folder/my-doc <-- Good HTTP://API.EXAMPLE.ORG/my-folder/my-doc <-- Bad ``` - Không dùng CRUD function names cho route URI (optional tùy vào muốn theo chuẩn hay muốn readability) ``` HTTP GET /device-management/managed-devices // Get all devices HTTP POST /device-management/managed-devices // Create new Device HTTP GET /device-management/managed-devices/{id} // Get device for given Id HTTP PUT /device-management/managed-devices/{id} // Update device for given Id HTTP DELETE /device-management/managed-devices/{id} // Delete device for given Id ``` - Không đem thông tin nhạy cảm lên query params (password, database name, table name,...) ``` /login?username=quang.le&password=123456 <-- very bad /procedure?database=VerySensitiveDatabase <-- Bad bad bad ```