-1

I have developed GET route handler for some endpoint (Eg: localhost:4200/app/all) .When i tried this in browser url, it gives me the intended data.But if i have any POST request endpoints, it does not work.Obviously i have no idea how request body is taken here.I have concluded that the browser works only for get request.Is this right,does the browser always make the GET request ?? Or we can also send POST requests ??

3 Answers3

2

Browsers typically can only send GET requests (when you enter a URL and press enter). To make POST requests to an endpoint.

To make post requests, there are a couple of ways:

  1. Use Postman: This is an amazing GUI that you can use to make any HTTP Requests to any endpoint
  2. Use cURL CLI: This is a very powerful command line to make HTTP requests. Reference
Yash Shah
  • 101
  • 5
1

When you type a URL in the address bar of your browser, it performs a GET request to retrive the content at the specified end-point.

If you want it to perform a POST request you can either create a form with method POST or use a JavaScript function (e.g. fetch) with the necessary arguments.

For more information:

1

The browser per default makes GET requests since that is what it is doing, it is getting stuff. POST-requests can be made from the browser using javascript (ie XHR/Fetch) or when using html forms with the method-attribute.

<form action="/form-endpoint" method="POST">
  <input type="text" id="username" name="username">
</form>
Karl-Johan Sjögren
  • 14,076
  • 7
  • 55
  • 62