Linux curl command examples 2018-06-21 05:21

curl is a good tool to help you make a request. Before introducing how to use it we need to start a server which receives the requests. I use Spring Boot as a simple server. The code is like following.

public class CurlExampleController {
    @RequestMapping(value = "/hello", method = RequestMethod.GET)
    public String hello(@RequestParam(value = "name") String name) {
        return "Hello " + name + "\n";

    @RequestMapping(path = "/post-json", method = RequestMethod.POST)
    public String postXml(@RequestBody User user) throws IOException {
        return user.toString();

    public static void main(String[] args) {, args);

Use curl to make Get request and post json to server.

[root@virtual tmp]# curl
Hello henry
[root@virtual tmp]# curl --header "Content-Type: application/json" --request POST --data '{"name":"henry","age":29}'
User{name='henry', age='29'}