Reputation: 188
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
})
Upvotes: 1
Views: 467
Reputation: 12900
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
Upvotes: 2