Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

404 error when post in Postman

Tags:

spring

postman

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);
    }

}
like image 708
Rômulo Sorato Avatar asked Feb 25 '18 03:02

Rômulo Sorato


People also ask

How do I fix REST API 404?

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.

What does post 404 mean?

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.

What does 404 mean in API?

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.


1 Answers

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.

like image 170
Chaitanya Avatar answered Oct 03 '22 16:10

Chaitanya