[英]NodeJS send HTTP code status to front-end
I am reading expressjs documentation and i sow that the response
to the user can be sent like this:我正在阅读 expressjs 文档,并且我认为可以像这样发送对用户的
response
:
res.status(404).send('Sorry, we cannot find that.') //or res.status(201).send('posted')
I want to know if according to best practices, is ok to send the s http status code
like this:我想知道根据最佳实践,是否可以像这样发送 s
http status code
:
res.send({ data: { user: "John }, statusCode: 201, message: "POsted success" })
It is ok the last structure or it exist another way to send data about the status?可以是最后一个结构还是存在另一种发送有关状态的数据的方式?
PS: I am new to node js PS:我是节点js的新手
The send
method doesn't use a statusCode
property on the body parameter to determine what the status code should be. send
方法不使用 body 参数上的statusCode
属性来确定状态代码应该是什么。
Not only is it not best practise, it simply doesn't work.它不仅不是最佳实践,而且根本行不通。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.