Windows Command Prompt treats quotes differently when compared to the Unix shell and this causes an error when the developer tries to create a new person using cURL to post data.
> curl -X POST -d '{"firstName": "Bilbo", "lastName": "Baggins"}' -H 'Content-Type:application/json' localhost:8080/people
curl: (6) Could not resolve host: Bilbo,
curl: (6) Could not resolve host: lastName
curl: (3) [globbing] unmatched close brace/bracket in column 8
{"cause":null,"message":"No suitable HttpMessageConverter found to read request body into object of type class hello.Person from request with content type of application/x-www-form-urlencoded;charset=UTF-8!"}
The solution is to change the single quotes to double quotes and escape properly que double quotes inside the data:
> curl -X POST -d "{\"firstName\": \"Bilbo\", \"lastName\": \"Baggins\"}" -H "Content-Type:application/json" localhost:8080/people
{
"firstName" : "Bilbo",
"lastName" : "Baggins",
"_links" : {
"self" : {
"href" : "http://localhost:8080/people/1"
},
"person" : {
"href" : "http://localhost:8080/people/1"
}
}
}
The previous command works on Windows and also on the Unix shell. Also that's the way it's described in the cURL manual:
If you want the parameter to contain spaces, you must enclose the entire
parameter within double quotes ("). Within those quotes, you specify a
quote as ".
This is not a huge problem and also makes the command a little harder to read and to write, but it made review all my code from the tutorial many times, since I thought I was leaving something behind. I think this could happen to others too, since this tutorial is aimed for people who are new to Spring.