Miscellenous Flashcards

(1 cards)

1
Q

Get and Post Request

A

get request :

used when we want to get some response to client or browers who send a request in form of url or routes

A GET request is like saying: ‘Get me a response when I visit this URL.’

data (response) is send in form of query strings
A query string is the part of a URL that carries extra data (key-value pairs) sent to the server in a GET request.
its like get me a response ohh wait take these extra data(information) with you so that you can provide better result or response

its like giving extra instruction ot cook on zomato so he can prepare food better for you

downpoints of query strings are:

1) they are limited i.e. only limited no of info can be send in form of request this is beacuse brower set a length of url can be this much only i.e fixed length futher length not allowed
2)the data becomes string and the data is visible in the url if its a sensitive data like passwords or credit card pin then there a issuse

note : data that comes with the get request can be accessed througth req.query or it is stored in req.query property

Post request :

used to post(send) something(pdf,password,credential etc) to the sever it is used to create,write & update data at the server

the data is not limited to string and can be of any form json,html string etc

data is send in form of request body

there is differnce inwhich data is accesed adn seen in get and post request

note: data needed to be parsed in both get and post just that in get it happens automatically and in post we need to add middlewares

get request : data in get is automatically parsed from string to js object so node js can use them and is stored in the req.query

post request : data in the post request is stored in the req.body but unparsed to make use of this data we need to parse it throught these code

app.use(express.urlencoded({extended:true}))
app.use(express.json())

this convert the string data of post request to js object so that we can use it

How well did you know this?
1
Not at all
2
3
4
5
Perfectly