I use Staticman (staticman.net) for comments on my Gatsby (gatsbyjs.org) site.
I've been using a classic HTML form with method="POST"
and action="https://api.staticman.net/..."
parameter, as this is what Staticman expects (docs).
However I'd like to make this more "React", and I've changed the form action to a handleSumbit()
function:
handleSubmit(event) {
event.preventDefault()
fetch("https://api.staticman.net/...", {
method: "POST",
body: event.target,
})
}
I feel that this doesn't work because the API expects an HTTP POST request, with an application/x-www-form-urlencoded
content-type, whereas my event.target
is a form with loads of React information.
How can I make my fetch()
request look exactly like an HTTP POST form submission?