Describe your issue in detail here.
In the below code i have this snippet of code
"app.post(‘/api/shorturl’, function(req, res) {
res.json({message:‘Success’})
}) "
when posting the url it is showing as “Cannot GET /api/shorturl” in the replit I don’t understand why
It looks like there might be an issue with the way you’re testing the /api/shorturl endpoint. The error “Cannot GET /api/shorturl” usually indicates that you are trying to access the endpoint using a GET request instead of a POST request.
In your code, the /api/shorturl endpoint is defined as a POST endpoint, so you should be making a POST request to it. If you are trying to test it from a web browser by entering the URL, the browser will send a GET request by default.
To test your endpoint, you can use a tool like Postman or curl, or you can modify your code to handle both GET and POST requests for that endpoint. For example:
This modification uses the app.route method to define the /api/shorturl endpoint for both GET and POST requests. Now, if you access it from a web browser, you should see a response for the GET request as well.
Make sure you are testing the POST request properly, and the “Cannot GET /api/shorturl” error should no longer appear for that endpoint.