Skip to content

Instantly share code, notes, and snippets.

@NSLog0
Last active September 16, 2018 04:18
Show Gist options
  • Save NSLog0/c7e5e32bc2bf009c2c2acc6e4b9c1266 to your computer and use it in GitHub Desktop.
Save NSLog0/c7e5e32bc2bf009c2c2acc6e4b9c1266 to your computer and use it in GitHub Desktop.
http-rest-tut-article
Resource GET (Read) POST (Create) PUT (update) DELETE (Delete)
/books ดึงข้อมูลหนังสือทั่งหมด สร้างหนังสือใหม่ อัพเดตข้อมูลหนังสือทั่งหมด ลบหนังสือทั่งหมด
books/2 /books/{:id} ดึงข้อมูลหนังสือตามไอดี ไม่อนุญาตให้เข้าถึง (HTTP 405) อัพเดตหนังสือตามไอดี ลบหนังสือตามไอดี
/books/authors ดึงข้อมูลผู้แต่งหนังสือทั่งหมด สร้างข้อมูลผู้แต่งหนังสือ อัพเดทข้อมูลผู้แต่งหนังสือทั่งหมด ลบผู้แต่งหนังสือทั่งหมด
GET /api/v1/books?state=true
GET /api/v1/books?fields=name,price,author,type,categories
GET /api/v1/books?fields=name,price,author,type,categories&sort=asc&page=1&limit=10
200 OK – [GET]
201 CREATED – [POST/PUT/PATCH]
204 NO CONTENT – [DELETE]
304 NOT MODIFIED
400 INVALID REQUEST – [POST/PUT/PATCH]
401 UNAUTHORIZED
403 FORBIDDEN
404 NOT FOUND
500 INTERNAL SERVER ERROR
/getAllBook
/createBook or /create/book
/book/remove or /removeBook/:id or /removeAllBook
GET /users?username=xx&password=xx
GET /users/2/?active
GET /users/2/active
ใช้ /books แทน /book
ใช้ /authors แทน /author
ใช้ /groups แทน /group
ใช้ /settings แทน /setting
ดึงข้อมูล สร้างข้อมูล อัพเดตข้อมูล ลบข้อมูล
GET POST PUT DELET
$.ajax({
url: "http://localhost/api/books/2",
type: "POST",
data: JSON.stringify(data),
headers: {
"Content-Type": "application/json",
"X-HTTP-Method-Override": "PUT" },
})
GET /books/2/author ดึงข้อมูลของผู้แต่งของหนังสือหมายเลข 2
GET /books/2/author/10 ดึงข้อมูลผู้แต่งหมายแลข 10 ที่หนังสือหมายเลข 2
app.use(function (req, res, next) {
res.contentType('application/json');
next();
});
app.use(app.router);
/api/v1/books/authors
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment