Skip to content

Merge searchParams with what is specified in input URL #836

@marshall007

Description

@marshall007

This is not a bug because the behavior is documented in the README:

Search parameters to include in the request URL. Setting this will override all existing search parameters in the input URL.

Nevertheless, I think this behavior is unintuitive. We are in the process of migrating a large codebase from axios -> ky and this difference is difficult to accommodate.

It would make more sense to me if the default behavior was to merge URLSearchParams specified in the input URL with anything specified in options.searchParams. It would be easy to reintroduce the current behavior with a beforeRequest hook that rewrites the request URL based on options.searchParams, if desired.

await ky.post('/example?foo=bar', {
  searchParams: {
    id: 'id'
  }
});

// Expected: -> POST /example?foo=bar&id=id
// Actual: -> POST /example?id=id

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions