DEV Community

Cui Mingda
Cui Mingda

Posted on

How to test Restful API with curl

GET请求,获取列表

curl http://localhost:3000/posts
Enter fullscreen mode Exit fullscreen mode

POST请求,新增一条记录

curl --header "Content-Type: application/json; charset=UTF-8" \
--request POST \
--data '{"title":"xyzzzz", "content":"xyzxxxxxx"}' \
http://localhost:3000/posts
Enter fullscreen mode Exit fullscreen mode

DELETE请求,删除一条记录

curl --request DELETE http://localhost:3000/posts/234
Enter fullscreen mode Exit fullscreen mode

PATCH请求,更新一条记录

curl --header "Content-Type: application/json; charset=UTF-8" \
--request PATCH \
--data '{"title": "xyzzzz"}' \
http://localhost:3000/posts/602396e1e6b7a60502ce1e79
Enter fullscreen mode Exit fullscreen mode

References

Top comments (1)

Collapse
 
divide_r_conquer profile image
Yuehui Ruan

可以👌🏼 加油💪🏻