ilokesto

Uploads and forms

OpenAPI request bodies often describe more than JSON. Fetcher keeps those body forms explicit in the shortcut request.

Multipart upload

await api.post('/uploads/{uploadId}', {
  params: {
    path: { uploadId: 'avatar' },
  },
  headers: {
    'x-upload-token': uploadToken,
  },
  formData: {
    file,
    visibility: 'private',
  },
});

Do not set the multipart Content-Type header yourself unless you know exactly why. The platform needs to add the boundary.

URL-encoded form

await api.post('/sessions', {
  formUrlEncoded: {
    username,
    password,
    scope: ['read', 'write'],
  },
});

Arrays become repeated keys. Boolean and number values are stringified. undefined entries are skipped.

Prebuilt bodies

If you need full control, pass a FormData, URLSearchParams, or explicit body through ky options.

const body = new FormData();
body.append('file', file);

await api.post('/uploads/{uploadId}', {
  params: { path: { uploadId: 'manual' } },
}, {
  body,
});

On this page