Technologies:
Tolerim
24 days ago
Axios encountered a "Not Found" error when attempting to send a POST request to http://localhost:4000/places.
The author of this post is requesting assistance with making a POST request to an endpoint ("/places"), but keeps getting an axios error. They have console logged the error, which shows a 404 bad request status code. The code for the POST request is included and all the fields are within the author's MongoDB schema. They have tried using FETCH instead of axios, but the same error occurred. The author has also included the payload within the network console log and it appears to be correct, but the preview is showing "CANNOT POST PLACES". They are asking for help to resolve this issue and apologize for the lengthy post.
Answers(2)
Vogi
23 days ago
Verified Answer
I'm sorry to hear that. A 404 error is usually returned when the server cannot find the requested resource. This could be due to a number of reasons such as incorrect URL or endpoint, incorrect HTTP method used, or the resource was deleted or moved.
If you are sure that the URL and endpoint are correct, then it could be that the server is not configured to handle the request. You can try checking if the server is running and if it is configured to handle requests on the specified port.
You can also check if there are any CORS (Cross-Origin Resource Sharing) issues. CORS is a security feature implemented by browsers that prevents web pages from making requests to a different domain than the one that served the web page.
I hope this helps. Let me know if you have any other questions.
Sources
API call returns 400 bad request even when the request is correct?What is a 400 Bad Request Error (and How Can I Fix It)? - How-To Geekreactjs - axios.post request gets 404 - Stack OverflowAxios catch error Request failed with status code 404Axios returns 404 for live, valid URL #3011 - GithubTolerim
24 days ago
It looks like you are trying to make a POST request to an endpoint ("/places") but keep getting an Axios error with a status code of 404. This means that the URL you are trying to access does not exist. Here are some things you can try:
- Make sure that the endpoint URL ("/places") is correct and matches the one in your server code.
- Check that your server is running and accessible from the same network that your front-end code is running on.
- You can try to test the endpoint with a tool like Postman to make sure that it's working correctly on the server-side.
- Double-check that you have imported the Place schema correctly into your index.js file.
- Verify that you have access to the endpoint with your current user's permissions. Check if you need to be authenticated to access it.
Regarding your code, everything looks fine to me, and you are sending the correct payload to the server. You seem to be using axios and fetch correctly, too. Do some investigation on the above points, and you may sort out the issue in no time.