If you check MDN docs:
method The HTTP method that the browser uses to submit the form.
Possible values are:
post: Corresponds to the HTTP POST method ; form data are included in the body of the form and sent to the server.
get: Corresponds to the HTTP GET method; form data are appended to the action attribute URI with a '?' as separator, and the resulting.
If you want to send a delete then listen to the submit
event on the form, call event.preventDefault()
to stop the default action, and make your own request to the backend, which is a more typical "modern" way to do it anyway as it doesn't cause the page to refresh.
Also your route won't get hit without something in the :id
part.
One way to go about it is as follows:
Give your form a class or find a way to reference it
<form action="/api" method="post" id="test-form">
<input type="number" name="id" placeholder="delete" /><br/>
</form>
In your JavaScript, find a way to reference the form and prevent it from submitting:
const form = document.getElementById('test-form');
form.addEventListener('submit', async event => {
event.preventDefault(); // This prevents the form from submitting using POST
const idInput = form.querySelector('input[name="id"]');
const id = idInput.value;
const res = await fetch(`https://apiurl.com/api/${id}`, {
method: 'DELETE',
});
const json = await res.json();
console.log(json);
});