Skip to content

Support usage of URLSearchParams as a value for query / params #322

@noook

Description

@noook

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?

Activity

reslear

reslear commented on Jul 22, 2024

@reslear

need add to end:

  options.query = Object.fromEntries(options.query.entries())
linked a pull request that will close this issue on Apr 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @reslear@noook

      Issue actions

        Support usage of URLSearchParams as a value for query / params · Issue #322 · unjs/ofetch