FG
๐Ÿ”Œ APIs & SDKs

Request params are not getting merged with instance params

Freshabout 20 hours ago
Mar 14, 20260 views
Confidence Score95%
95%

Problem

Describe the bug Specific request params do not get merged with the instance default params. To Reproduce [code block] [code block] What happens is that the request param object overrides the instance default param object. The instance no longer has a query param of `q`. Expected behavior According to the docs, all configuration options are merged. https://github.com/axios/axios#instance-methods I expected request to contain both `q` and `page` params. This is also how it was working in version 0.18.0, which is how I noticed. Environment: - Axios Version: 0.19.0 - OS: 10.14.5 (18F132) - Browser: Node Express, and Chrome - Browser: Node 10.15.0, Chrome Version 74.0.3729.169 (Official Build) (64-bit)

Unverified for your environment

Select your OS to check compatibility.

1 Fix

Canonical Fix
Unverified Fix
New Fix โ€“ Awaiting Verification

Merge Request Params with Instance Params in Axios

Medium Risk

In Axios version 0.19.0, the request parameters are overriding the instance default parameters instead of merging them. This behavior deviates from the expected merging functionality described in the documentation, leading to the loss of default parameters such as 'q'.

Awaiting Verification

Be the first to verify this fix

  1. 1

    Update Axios Version

    Upgrade Axios to the latest version where the merging behavior has been fixed. This ensures that request parameters are merged correctly with instance parameters.

    bash
    npm install axios@latest
  2. 2

    Check Parameter Merging Logic

    Review the code where the Axios instance is created and ensure that the parameters are being set correctly. Use the spread operator to merge instance defaults with request parameters.

    typescript
    const instance = axios.create({ params: { q: 'defaultQuery', page: 1 } });
    const response = await instance.get('/endpoint', { params: { page: 2 } }); // This should merge 'q' and 'page'
  3. 3

    Test Merged Parameters

    Create a test case to verify that both 'q' and 'page' parameters are present in the request. This will confirm that the merging behavior is functioning as expected.

    typescript
    const params = { q: 'test', page: 2 };
    const response = await instance.get('/endpoint', { params });
    console.log(response.config.params); // Should log { q: 'test', page: 2 }
  4. 4

    Review Documentation

    Ensure that the implementation aligns with the latest Axios documentation regarding parameter merging. This will help prevent similar issues in the future.

    none
    https://github.com/axios/axios#instance-methods

Validation

Confirm that the request contains both 'q' and 'page' parameters by logging the request configuration or using a debugging tool. Ensure that the test case created passes successfully.

Sign in to verify this fix

Environment

Submitted by

AC

Alex Chen

2450 rep

Tags

axioshttpapi