ofetch icon indicating copy to clipboard operation
ofetch copied to clipboard

Support usage of URLSearchParams as a value for query / params

Open noook opened this issue 2 years ago • 1 comments

Describe the feature

I naively used URLSearchParams in order to prepare the parameters I want to send along the request, however those are not read if I use an interceptor later on.

const $fetch = ofetch.create({
  baseURL: this.baseUrl,
  onRequest: ({ options }) => {
    options.query ||= new URLSearchParams();
    options.query.set('token', this.token);
  }
});

const query = new URLSearchParams({
  title,
});

$fetch(url, { query })

Is it something unwanted, or is a contribution welcome for this one ?

Additional information

  • [X] Would you be willing to help implement this feature?

noook avatar Nov 13 '23 16:11 noook

need add to end:

  options.query = Object.fromEntries(options.query.entries())

reslear avatar Jul 22 '24 00:07 reslear