Skip to content

Encoding data for POST requests

I'm grateful that Jake Archibald has taken the time to cover some of the browser's built-in APIs for managing form data. I've been building forms for years, and I still learned a lot from this post, particularly around FormData and how fetch handles different body object types.

On a tangentially related note, I've been tootling around with for a personal project, and one of the core design decisions is to use native browser APIs whenever possible. It really is quite nice to be able to take a <form> element and convert it to a fetch request with minimal effort:

fetch(form.action, {
  method: form.method,
  body: new FormData(form),