简体   繁体   English

如何在feathers js的响应中返回非json数据?

[英]How to return non-json data in a response from feathers js?

I need to return a string without quotes in a response to a api request on a feathers js systems endpoint. 我需要在Feathers js系统端点上的api请求响应中返回不带引号的字符串。 I understand this should be possible using service specific middleware, but the documentation is not very clear on how to get one of these working within the feathers generated environment. 我知道可以使用特定于服务的中间件来做到这一点,但是有关如何使它们在羽毛生成环境中正常工作的文档尚不十分清楚。 Can someone provide an example of how this would work with the generated structure of the current feathers js system? 有人可以提供一个示例说明如何将其与当前feathers js系统的生成结构一起使用吗?

Ive tried stumbling through tearing apart the one example within the documentation, nothing i have tried has been successful or even worth mentioning here, i feel im a bit too confused by the documentation on this subject. 我已经尝试过通过分解文档中的一个示例来绊脚石,我尝试过的任何事情都没有成功,甚至在这里也不值得一提,我对此主题的文档感到有些困惑。

current output - "response" 当前输出-“响应”

output needs to be - response 输出需要-响应

Service specific middleware can be added where app.use('/servicename', service) for your service is called (eg here in the chat application messages service ). 可以在app.use('/servicename', service)服务的app.use('/servicename', service)地方添加特定于服务的中间件(例如,在聊天应用程序消息服务中 )。 It can then be used as documented: 然后可以将其用作文档:

app.use('/messages', createService(options), (req, res) => {
  // res.data is the response
  res.end('Got data: ' + res.data.text);
});

It is also possible to register a global formatter that applies to all responses. 也可以注册适用于所有响应的全局格式化程序

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM