Difference between response.status () and response.sendStatus () in expression

What is the difference between response.status()and response.sendStatus()in the Express.

I notice that it is commonly used for mail, recipient, and other middleware, and is later used in removal requests. Why is this?

+10
source share
3 answers

status() sets the http status in the response (as a server side javascript object)

sendStatus() both set the status and send it to the client

http-. sendStatus, , (, ​​ HTTP-).

:

https://expressjs.com/en/4x/api.html#res.sendStatus

+14

, sendStatus .

, , status. , JSON, , , ( status), JSON ( send). sendStatus, JSON , .

+3

Based on the provided @freakish link

res.sendStatus(200); // equivalent to res.status(200).send('OK')
res.sendStatus(403); // equivalent to res.status(403).send('Forbidden')
res.sendStatus(404); // equivalent to res.status(404).send('Not Found')
res.sendStatus(500); // equivalent to res.status(500).send('Internal Server Error')
0
source

Source: https://habr.com/ru/post/1649324/


All Articles