【问题标题】:How to write delete method using POST request - REST - Nest JS如何使用 POST 请求编写删除方法 - REST - Nest JS
【发布时间】:2019-11-05 23:36:29
【问题描述】:

如何使用 api 中的 post 请求删除数据库中的 id 或记录

从数据库中删除一个指南

@Delete('/:id')
deleteGuide(@Param('id') id: string): Promise<void> {
    return this.guidesService.deleteGuide(id);
}

【问题讨论】:

  • 您的 GuidesService 是什么样的?您使用的是什么数据库或 ORM?
  • 您是在尝试使用 POST 请求还是 DELETE 请求?代码 sn-p 显示 HTTP DELETE,但您的问题与 HTTP POST 有关,这会造成一些混乱。
  • async deleteGuide(id: string): Promise{ const result = await this.guideRepository.delete(id); if(result.affected === 0){ throw new NotFoundException(Guide with ID "$id" not found);这就是我的 GuidesService 的样子,而且我正在使用 PostgreSql @KimKern
  • 我正在尝试使用 POST 请求删除数据库中的记录@JayMcDoniel
  • 您要访问哪个 URL?如果要使用 POST 请求,则需要将装饰器更改为 @Post(':id') 而不是 DELETE。

标签: javascript rest post crud nestjs


【解决方案1】:

你可以的

@Post('/:id')
deleteGuide(@Param('id') id: string): Promise<void> {
    return this.guidesService.deleteGuide(id);
}

【讨论】:

    猜你喜欢
    • 2022-12-10
    • 2013-03-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-28
    • 2021-01-25
    相关资源
    最近更新 更多