Defining RESTful Routes Flashcards

1
Q

What is a get request?

A

Get requests are used to get information and when we submit, if we have data that is being sent alongside it is in the query string (url). Limited amount of data can be sent. Should be no side effects on back end like things being created/updated.

Submit
Now if we add some data in the form on browser we’ll get information in query string.

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

What is a post request?

A

Posting data to the server. Used if we have information that is important that we need to send as part of the request and it won’t be sent in query string, instead it will be sent in the request body. Means we can send more data and of any type like json.

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

How would we use post in Express?

A

app.post(‘/tacos’, (req, res) => {res.send(“Post /tacos response”) }

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

How would we extract data from the request body of a post and do something with it?

A

req includes a property called req.body. Contains key value pairs of data submitted in the request body. By default is undefined. It is populated when we use body-parsing middleware such as express.json() or express.urlencoded().

app. use(express.urlencoded({extended:true}
app. use is a function that runs on every single request.

We can destructure from it as well.
app.post(‘/tacos’, (req, res) => {
const {meat, qty } = req.body
res.send(Ok here are your ${qty} ${meat} tacos.) }

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

What is REST?

A

Basically set of guidelines for how a client-server should communicate with each other.

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