I am confused between app.get()
and app.post()
. Also when to use them?
Asked
Active
Viewed 97 times
-2

jonrsharpe
- 115,751
- 26
- 228
- 437

ramkrushna
- 17
- 5
2 Answers
0
Hi, in API we use
- GET to get data
- POST to add data
- PUT to edit data
- PATCH to edit data
- DELETE to delete data

Kareem Adel
- 371
- 2
- 10
-
to get data from where? – ramkrushna Feb 25 '22 at 13:49
-
from API like if you need data about users you can make get req to "/users/" – Kareem Adel Feb 25 '22 at 13:51
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