unjs / ofetch

😱 A better fetch API. Works on node, browser and workers.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support usage of URLSearchParams as a value for query / params

noook opened this issue · 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

  • Would you be willing to help implement this feature?