I´m trying to send a POST request that is an Person
object that contains a list of contacts.
But I don´t know if this is the correct syntax to send a list:
{
"name":"romulo",
"contacts" : [
{
"contact" : "3466577"
},
{
"contact" : "532423"
}
]
}
But keeps me returning a 404 error
what i´m doing wrong?
post method:
@PostMapping("/person")
public void addPerson(@Valid @RequestBody Person person) {
Person savedPerson = personRepository.save(person);
List<Contact> contacts = person.getContacts();
for (Contact contact1 : contacts) {
contactRepository.save(contact1);
}
}
You fix this by opening the listen step in your VSM file, and changing the base path in there, so you don't get a 404 error. You could change that to "/api/" so any api requests are dealt-with, or "/api/retrieveId/" so only retrieveId messages are dealt-with, or "/" so all requests are dealt-with.
The HTTP 404 Not Found response status code indicates that the server cannot find the requested resource. Links that lead to a 404 page are often called broken or dead links and can be subject to link rot.
404 means The server has not found anything matching the Request-URI. If you put in the wrong URI or bad URI that is your problem and the reason you didn't get to a resource whether a HTML page or IMG.
HTTP 404 is returned when the server is unable to find method to match your exact request.
For the mentioned request have the url as http://<context>/requestpath
with request method as POST.(http://localhost:8080/person
)
Check the request body and all the fields should exactly match the Person object else it may return HTPP 400.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With