0

It is a simple code for sending a post request to a server but when I hit the end point it shows [Cannot get / "endpoint"]. However, when I send a get request, server responds with message "Ok". Please help me out here that what I am missing.

import express from 'express'
import bodyParser from 'body-parser'

const app = express();
app.use(bodyParser.urlencoded({ extended: true }));

app.post('/post', (req, res) => {
    console.log('Got body:', req.body);
    res.sendStatus(200);
});

app.listen(8080, () => console.log(`Started server at http://localhost:8080!`));`

Below is my Packago.json file.

enter image description here

The message I receive while hitting the endpoint is shown below

.enter image description here

  • 1
    When you open a URL in your browser, it is a GET request. Use a client like Postman to easily make a POST request – Phil Jan 31 '23 at 05:40
  • Does this answer your question? [How to manually send HTTP POST requests from Firefox or Chrome browser](https://stackoverflow.com/questions/4797534/how-to-manually-send-http-post-requests-from-firefox-or-chrome-browser) – Phil Jan 31 '23 at 05:41
  • @phil , Thank you man, I got the point and got the response as well. – Muhammad Junaid Jan 31 '23 at 05:46

1 Answers1

-2

When we open a URL on a browser, that is a GET request and we want to read data. As far as POST request is concerned we have to use an API platform such as Postman to make a POST request as we submit our data to the server. That's it.

  • API testing tools are a convenience when it comes to testing GET or POST requests. You can run tests using simple chrome browser and developer tools as well. A browser is an application that allows you to send ANY type of request and receive its response. Tools like postman make it easier to customise parameters and make the task more 'developer-friendly'. – Amogh Sarpotdar Feb 02 '23 at 02:30