-2

I am confused between app.get() and app.post(). Also when to use them?

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
ramkrushna
  • 17
  • 5

2 Answers2

0

Hi, in API we use


  1. GET to get data
  2. POST to add data
  3. PUT to edit data
  4. PATCH to edit data
  5. DELETE to delete data
Kareem Adel
  • 371
  • 2
  • 10
0

When using the HTTP protocol, we use different URLs to retrieve, add, update or delete information. To specify which action we want to perform we add to the URL the HTTP method (also called as HTTP verb).

2 popular HTTP verbs are:

  • GET - indicate we want to retrieve / get information (e.g. get information about a user).
  • POST - indicate we want to post / add new information (e.g. add a new user).

In ExpressJS framework we register a handler function (known as a middleware) for each possible route that our app should handle.

to register a handler function to a route that uses the GET method, we use:

.get(<route>, <middleware>)

and to register a handler function to a route that uses the POST method, we use:

.post(<route>, <middleware>)
Idan Krupnik
  • 443
  • 1
  • 6
  • 8