【问题标题】:Overriding http methods in fastify在 fastify 中覆盖 http 方法
【发布时间】:2020-12-12 15:25:58
【问题描述】:

我正在使用 fastify 和 TypeScript 在节点中创建一个 CRUD 应用程序。如何覆盖 html 表单中的 rest 方法?

例如在 Html 中:

<form action="/removeproduct" method="DELETE">
   <input type="text" name="productname" />
</form>

并且在节点fastify代码中:

app.delete('/removeproduct', (request, reply) => {
  // code to remove a product from db
})

【问题讨论】:

标签: html node.js forms webmethod fastify


【解决方案1】:

你不能这样,因为标准定义你只能使用 GET 和 POST:https://www.w3schools.com/tags/att_form_method.asp

要存档,您应该在 html 页面中提交时调用 javascript 函数。然后使用fetch 编写您自己的ajax 调用。这样您就可以在 REST API 标准中声明所有方法

【讨论】:

    猜你喜欢
    • 2013-10-03
    • 2011-02-19
    • 1970-01-01
    • 1970-01-01
    • 2017-02-16
    • 1970-01-01
    • 1970-01-01
    • 2011-02-02
    • 2010-11-06
    相关资源
    最近更新 更多