1

I am creating a CRUD app in node with fastify and TypeScript. How can I override rest methods in html forms?

For example in the Html:

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

And in the node fastify code:

app.delete('/removeproduct', (request, reply) => {
  // code to remove a product from db
})
talopl
  • 188
  • 1
  • 9
  • 1
    Does this answer your question? [Using PUT method in HTML form](https://stackoverflow.com/questions/8054165/using-put-method-in-html-form) – Mike Aug 27 '20 at 22:41

1 Answers1

2

You can't in this way since the standard define that you can use GET and POST only: https://www.w3schools.com/tags/att_form_method.asp

To archive that you should call a javascript function on submit in the html page. Then write your own ajax call using fetch. In this way you will be able to declare all the methods in the REST API standard

Manuel Spigolon
  • 11,003
  • 5
  • 50
  • 73