練習 TodoList RESTful API
View Demo
Table of Contents
初學 Node.js 不使用框架建立 TodoList RESTful API
By Node.js 直播班 - 第八組
-
URL
/todos
-
Method:
GET
-
URL Params
None
-
Data Params
None
-
Success Response:
- Code: 200
Content:{ "status":"SUCCESS", "data":[ { "id":"uuid", "title":"example" } ,... ] }
- Code: 200
-
Sample Call:
curl --location --request GET 'https://demo.herokuapp.com/todos'
-
URL
/todos
-
Method:
POST
-
URL Params
None
-
Data Params
- Content-Type: application/json
{ "title":"example" }
-
Success Response:
- Code: 201
Content:{ "status":"SUCCESS", "data":[ { "id":"uuid", "title":"example" } ,... ] }
- Code: 201
-
Error Response:
- Code: 400 Bad Request
Content:{ "status":"ERROR", "massage":"json parser error or other error" }
OR
- Code: 415 Unsupported Media Type
Content:{ "status":"ERROR", "massage":"資料結構錯誤" }
- Code: 400 Bad Request
-
Sample Call:
curl --location --request POST 'https://demo.herokuapp.com/todos' \ --header 'Content-Type: application/json' \ --data-raw '{ "title":"example" }'
-
URL
/todos
-
Method:
DELETE
-
URL Params
None
-
Data Params
None
-
Success Response:
- Code: 200
Content:{ "status":"SUCCESS", "data":[] }
- Code: 200
-
Sample Call:
curl --location --request DELETE 'https://demo.herokuapp.com/todos'
-
URL
/todos/:id
-
Method:
DELETE
-
URL Params
Required:
id=[todoId]
-
Data Params
None
-
Success Response:
- Code: 200
Content:{ "status":"SUCCESS", "data":[ { "id":"uuid", "title":"example" } ,... ] }
- Code: 200
-
Error Response:
- Code: 400 Bad Request
Content:{ "status":"ERROR", "massage":"json parser error or other error" }
OR
- Code: 404 Not Found
Content:{ "status":"ERROR", "massage":"待辦事項不存在" }
- Code: 400 Bad Request
-
Sample Call:
curl --location --request DELETE 'https://demo.herokuapp.com/todos/f35f2a71-e3f6-407c-a287-eff76f27c224'
-
URL
/todos/:id
-
Method:
PATCH
-
URL Params
Required:
id=[todoId]
-
Data Params
None
-
Success Response:
- Code: 200
Content:{ "status":"SUCCESS", "data":[ { "id":"uuid", "title":"example" } ,... ] }
- Code: 200
-
Error Response:
- Code: 400 Bad Request
Content:{ "status":"ERROR", "massage":"json parser error or other error" }
OR
-
Code: 404 Not Found
Content:{ "status":"ERROR", "massage":"待辦事項不存在" }
OR
- Code: 415 Unsupported Media Type
Content:{ "status":"ERROR", "massage":"資料結構錯誤" }
- Code: 400 Bad Request
-
Sample Call:
curl --location --request PATCH 'https://demo.herokuapp.com/todos/f0ad588a-c931-4612-8cad-ba5f6c969ff7' \ --header 'Content-Type: application/json' \ --data-raw '{ "title":"example" }'