ky icon indicating copy to clipboard operation
ky copied to clipboard

feat: add support for `stringifyJson`

Open Reverier-Xu opened this issue 2 months ago • 1 comments

When sending an HTTP request, this option allows the user to specify how the request data should be serialized as a string.

For example, it will be useful when users want to change the default serialization behavior using JSON.stringify(_, replacer).

import ky from 'ky';
import { DateTime } from 'luxon';

const json = await ky('https://example.com', {
  stringifyJson: data => JSON.stringify(data, (key, value) => {
    if (key.endsWith('_at')) {
      return DateTime.fromISO(value).toSeconds();
    }
    return value;
  })
}).json();

Reverier-Xu avatar Apr 21 '24 15:04 Reverier-Xu