如何在 Loopback 中包含文本请求正文?

How can I have a text request body in Loopback?

我有一个 api 端点,我想将其 post 文本作为主体。

我试过这个代码:

@post('/my-endpoint', {
    responses: {}
  })
  async createFromCsv(
    @requestBody({content: {'application/text': {}}}) csv: string,
){
  // code
}

但出现错误:

UnsupportedMediaTypeError: Content-type application/text is not supported.

我从这里找到的评论中拼凑了上面的代码:https://github.com/strongloop/loopback-next/blob/8ae8a0a81db205f052b81caaceece5303cd80ff2/packages/openapi-v3/src/decorators/request-body.decorator.ts#L68

如何获得文本请求正文?

原来我从评论中挑选的代码并不完全合理。

文本的正确内容类型是 text/plain

例如

@requestBody({content: {'text/plain': {}}}) csv: string

还有text/csvtext/html

在此处了解有关 MIME 类型的更多信息 (https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types)