api restful service ứng dụng đọc truyện bằng java jersey
Ứng dụng đọc truyện
Chức năng
Mô tả hệ thống
Backend
Front-end
Phần mềm quản trị
Người dùng cuối
Yêu cầu
Lấy thông tin danh sách các truyện
URL
/book
Authentication
No
Method:
GET
URL Params
Optional:
start=[0-~] unsigned integer default:0
limit=[1-100] unsigned integer default:10
Success Response:
Code: 200
Content:
{
"result":
[
{
"id": 4,
"title": "Khí Phi Hồ Sủng",
"content": "Nội dung truyện Khí Phi Hồ Sủng"
},
{
"id": 5,
"title": "Mê Muội",
"content": "Nội dung truyện Mê Muội"
}
],
"message": "OK",
"status": 200
}
Error Response:
Code: 400 Bad Request
Content:
{
"message": "Empty data",
"status": 400
}
Sample Call:
GET
/book
GET
/book?start=1&limit=2
Lấy thông tin của 1 truyện cụ thể
URL
/book/{book_id}
Authentication
No
Method:
GET
Success Response:
Code: 200
Content:
{
"result":
{
"id": 10,
"title": "Tên truyện",
"content": "Nội dung truyện",
"category":
[
{
"name": "Ngôn Tình",
"id": 1
},
{
"name": "Truyện cười",
"id": 2
},
],
},
"message": "OK",
"status": 200
}
Error Response:
Code: 404 Not Found
Content:
{
"message": "Book not found",
"status": 404
}
Sample Call:
GET
/book/1
Thêm 1 truyện
URL
/book
Authentication
Yes
Method:
POST
Data Params
Required:
{
"title": {Tên truyện},
"content": {Nội dung truyện}
}
Success Response:
Code: 200
Content:
{
"result":
{
"id": 10,
"title": "Tên truyện",
"content": "Nội dung truyện"
},
"message": "OK",
"status": 200
}
Error Response:
Code: 400 Bad Request
Content:
{
"status": 400,
"message": "Duplicate content with book 2"
}
OR
{
"status": 400,
"message": "Invalid input data"
}
OR
{
"status": 400,
"message": "Can't insert this book"
}
Sample Call:
POST
/book
{
"title": "Con cò",
"content": "Con cò bay lả bay la"
}
Update 1 truyện
URL
/book/{book_id}
Authentication
Yes
Method:
PUT
Data Params
Required:
{
"title": {Tên truyện},
"content": {Nội dung truyện}
}
Success Response:
Code: 200
Content:
{
"result":
{
"id": 22,
"title": "Đỉnh Luyện Thần Ma 2",
"content": "Nội dung truyện đã chỉnh sửa"
},
"message": "OK",
"status": 200
}
Error Response:
Code: 400 Bad Request
Content:
{
"status": 400,
"message": "Duplicate content with book 2"
}
OR
{
"status": 400,
"message": "Invalid input data"
}
OR
{
"status": 400,
"message": "Can't update this book"
}
Sample Call:
PUT
/book/1
{
"title": "Con cò",
"content": "Con cò bay lả bay la"
}
Xóa một truyện
URL
/book/{book_id}
Authentication
Yes
Method:
DELETE
Success Response:
Code: 200
Content:
{
"status": 200,
"message": "Delete this book successful"
}
Error Response:
Code: 400 Bad Request
Content:
{
"status": 400,
"message": "This book doesn't exist"
}
OR
{
"status": 400,
"message": "Can't delete this book"
}
Sample Call:
DELETE
/book/1
Xem thông tin các thể loại của một truyện cụ thể
URL
/book/{book_id}/category
Method:
GET
Authentication
No
URL Params
Optional:
start=[0-~] unsigned integer default:0
limit=[1-100] unsigned integer default:10
Success Response:
Code: 200
Content:
{
"result":
[
{
"name": "Ngôn Tình",
"id": 1
},
{
"name": "Truyện Teen",
"id": 9
}
],
"message": "OK",
"status": 200
}
Error Response:
Code: 400 Bad Request
Content:
{
"status": 400,
"message": "This book doesn't exist"
}
OR
{
"status": 400,
"message": "Empty data"
}
Sample Call:
GET
/book/1/category
GET
/book/1/category?start=0&limit=2
Thêm thể một thể loại cho một truyện cụ thể
URL
/book/{book_id}/category
Authentication
Yes
Method:
POST
Data Params
Required:
{
"category_id": {category_id}
}
Success Response:
Code: 200
Content:
{
"status": 200,
"message": "Insert this category for this book successful"
}
Error Response:
Code: 400 Bad Request
Content:
{
"status": 400,
"message": "This book is already has this category"
}
OR
{
"status": 400,
"message": "Can't insert this category for this book"
}
Sample Call:
POST
/book/1/category
{
"category_id": 4
}
Set tất cả các thể loại của một sách
URL
/book/{book_id}/category
Authentication
Yes
Method:
PUT
Data Params
Optional:
Danh sách các category id (có thể nhận giá trị rỗng)
[
{
"id": {category_id}
},
{
"id": {category_id}
}
]
Success Response:
Code: 200
Content:
{
"result":
[
{
"name":"Truyện ma",
"id":1
},
{
"name":"Truyện cười",
"id":2
}
],
"message":"OK",
"status":200
}
OR
{
"message":"Delete all category of this book successful",
"status":200
}
Error Response:
Code: 400 Bad Request
Content:
{
"status": 400,
"message": "Category not found: 70"
}
OR
{
"status": 400,
"message": "Can't insert this category for this book"
}
Sample Call:
PUT
/book/1/category
[
{
"id": 4
},
{
"id": 5
}
]
Xóa tất cả các thể loại của một truyện cụ thể
URL
/book/{book_id}/category
Authentication
Yes
Method:
DELETE
Success Response:
Code: 200
Content:
{
"status": 200,
"message": "Delete all category of this book successful"
}
Error Response:
Code: 400 Bad Request
Content:
{
"status": 400,
"message": "This book has no category"
}
OR
{
"status": 400,
"message": "Can't delete all category of this book"
}
Sample Call:
DELETE
/book/1/category
Xóa một thể loại của một truyện cụ thể
URL
/book/{book_id}/category/{category_id}
Authentication
Yes
Method:
DELETE
Success Response:
Code: 200
Content:
{
"status": 200,
"message": "Delete this category of this book successful"
}
Error Response:
Code: 400 Bad Request
Content:
{
"status": 400,
"message": "This book is not has this category"
}
OR
{
"status": 400,
"message": "Can't delete this category for this book"
}
Sample Call:
DELETE
/book/1/category/2
Tìm kiếm truyện theo tên, nội dung hoặc thể loại
URL
/book/search
Authentication
No
Method:
GET
URL Params
Optional:
title = {tên truyện}
content = {nội dung truyện}
categories = {thể loại 1},{thể loại 2},{thể loại 3}
start=[0-~] unsigned integer default:0
limit=[1-100] unsigned integer default:10
Success Response:
Code: 200
Content:
{
"result":
[
{
"id":1,
"title":"Tên truyện 1",
"content":"Nội dung truyện 1"
},
{
"id":2,
"title":"Tên truyện 2",
"content":"Nội dung truyện 3"
}
],
"message":"OK",
"status":200
}
Error Response:
Code: 400 Bad Request
Content:
{
"status": 400,
"message": "Empty data"
}
OR
{
"status": 400,
"message": "Invalid input data"
}
Sample Call:
GET
/book/search?title=truyen&content=noidung&categories=1,2,3
Lấy thông tin tất cả các thể loại
URL
/category
Authentication
No
Method:
GET
URL Params
Optional:
start=[0-~] unsigned integer default:0
limit=[1-100] unsigned integer default:10
Success Response:
Code: 200
Content:
{
"result":
[
{
"name": "Ngôn Tình",
"id": 1
},
{
"name": "Xuyên Không",
"id": 2
}
],
"message": "OK",
"status": 200
}
Error Response:
Code: 400 Bad Request
Content:
{
"status": 400,
"message": "Empty data"
}
Sample Call:
GET
/category
GET
/category?start=1&limit=2
Lấy thông tin cụ thể của 1 thể loại
URL
/book/{category_id}
Authentication
No
Method:
GET
Success Response:
Code: 200
Content:
{
"result":
{
"name": "Ngôn Tình",
"id": 1
},
"message": "OK",
"status": 200
}
Error Response:
Code: 400 Bad Request
Content:
{
"status": 400,
"message": "This category doesn't exist"
}
Sample Call:
GET
/category/1
Thêm 1 thể loại
URL
/category
Authentication
Yes
Method:
POST
Data Params
Required:
{
"name": {Tên thể loại}
}
Success Response:
Code: 200
Content:
{
"result":
{
"name": "Tên thể loại",
"id": 17
},
"message": "OK",
"status": 200
}
Error Response:
Code: 400 Bad Request
Content:
{
"status": 400,
"message": "Duplicate content with category 2"
}
OR
{
"status": 400,
"message": "Invalid input data"
}
OR
{
"status": 400,
"message": "Can't insert this category"
}
Sample Call:
POST
/category
{
"name": "Truyện cười"
}
Update 1 thể loại
URL
/book/{category_id}
Authentication
Yes
Method:
PUT
Data Params
Required:
{
"name": {Tên thể loại mới}
}
Success Response:
Code: 200
Content:
{
"result":
{
"name": "Tên thể loại mới",
"id": 2
},
"message": "OK",
"status": 200
}
Error Response:
Code: 400 Bad Request
Content:
{
"status": 400,
"message": "Duplicate content with category 2"
}
OR
{
"status": 400,
"message": "Invalid input data"
}
Sample Call:
PUT
/category/1
{
"name": "Truyện cười"
}
Xóa một thể loại
URL
/category/{category_id}
Authentication
Yes
Method:
DELETE
Success Response:
Code: 200
Content:
{
"status": 200,
"message": "Delete this category successful"
}
Error Response:
Code: 400 Bad Request
Content:
{
"status": 400,
"message": "This category doesn't exist"
}
OR
{
"status": 400,
"message": "Can't delete this category"
}
Sample Call:
DELETE
/category/1
Xem danh sách các truyện thuộc một thể loại cụ thể
URL
/category/{category_id}/book
Authentication
No
Method:
GET
URL Params
Optional:
start=[0-~] unsigned integer default:0
limit=[1-100] unsigned integer default:10
Success Response:
Code: 200
Content:
{
"result":
[
{
"id": 7,
"title": "Ông Xã Là Trung Khuyển",
"content": "Nội dung truyện Ông Xã Là Trung Khuyển"},
{
"id": 17,
"title": "Gian Nịnh Quốc Sư Yêu Tà Thê",
"content": "Nội dung truyện Gian Nịnh Quốc Sư Yêu Tà Thê"
}
],
"message": "OK",
"status": 200
}
Error Response:
Code: 400 Bad Request
Content:
{
"status": 400,
"message": "This category doesn't exist"
}
OR
{
"status": 400,
"message": "Empty data"
}
Sample Call:
GET
/category/1/book
GET
/category/1/book?start=0&limit=2