DEV Community

Cui Mingda
Cui Mingda

Posted on

2

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

可以👌🏼 加油💪🏻

Qodo Takeover

Introducing Qodo Gen 1.0: Transform Your Workflow with Agentic AI

Rather than just generating snippets, our agents understand your entire project context, can make decisions, use tools, and carry out tasks autonomously.

Read full post