Axios.post Doesn't work in app, works in url
I am following the React-Redux tutorial. For my axios.post () does not work when the application starts, but if I use the same url and paste it into the browser address text field, it works. Why is this happening?
Here is the call in my application:
const request = axios.post(`${ROOT_URL}/posts/${id}${API_KEY}`);
Here is the error as shown in F12 in Chrome:
POST http://reduxblog.herokuapp.com/api/posts/120342?key=bob884 404 (Not found)
Why won't it succeed if it has a good URL? If you click on it, you will see the response in the browser:
{"id": 120342, "title": "SOLID", "categories": "OOP", "content": "SOLID is shorthand ..."}
source to share
When you click on the link, the browser sends a request to the server GET
.
The endpoint POST
may not be available from the server side at the specified URL.
Whenever the server cannot find the URL with the specified method ( GET
/ POST
), it returns an error 404 - Not found
. In this case, it does not find any method POST
defined for this address.
You should consider changing the method to request GET
if that's what you want.
source to share