feat: add support for the QUERY HTTP method by mahmoodhamdi · Pull Request #10579 · axios/axios · GitHub
Skip to content

feat: add support for the QUERY HTTP method#10579

Open
mahmoodhamdi wants to merge 1 commit intoaxios:v1.xfrom
mahmoodhamdi:feat/add-query-http-method
Open

feat: add support for the QUERY HTTP method#10579
mahmoodhamdi wants to merge 1 commit intoaxios:v1.xfrom
mahmoodhamdi:feat/add-query-http-method

Conversation

@mahmoodhamdi
Copy link
Copy Markdown

@mahmoodhamdi mahmoodhamdi commented Mar 29, 2026

Summary

Adds axios.query() and axios.queryForm() as shorthand methods for the QUERY HTTP method (RFC draft-ietf-httpbis-safe-method-w-body).

QUERY is a safe, idempotent method like GET but allows a request body — ideal for complex queries that don't fit in URL parameters.

Usage

// Send a QUERY request with a JSON body
const { data } = await axios.query('/search', {
  filter: { status: 'active', tags: ['urgent', 'open'] },
  limit: 50,
});

// With multipart/form-data
await axios.queryForm('/search', { filter: 'active' });

// Using generic config
await axios({ method: 'query', url: '/search', data: { q: 'test' } });

Changes

File Change
lib/core/Axios.js Add query to methods-with-data aliases (generates query + queryForm) and headers flattening list
lib/core/dispatchRequest.js Add query to content-type dispatch list
lib/defaults/index.js Add query to default headers initialization
index.d.ts Add query/QUERY to Method type, add query()/queryForm() to Axios class
index.d.cts Same TypeScript changes for CJS declarations
tests/unit/api.test.js Add query and queryForm to method existence checks
tests/unit/core/query-method.test.js Dedicated test suite for QUERY method

Testing

  • axios.query() sends QUERY request with JSON body
  • axios.queryForm() sends QUERY request with multipart/form-data
  • axios({ method: 'query' }) generic syntax works
  • Content-Type defaults applied correctly
  • API existence checks for both static and instance methods
  • All 308 unit tests pass, lint clean

Closes #5465


Summary by cubic

Adds support for the QUERY HTTP method to axios via axios.query() and axios.queryForm(). Enables safe, idempotent requests with a body for complex queries.

Description

  • Adds query to methods-with-data; generates query/queryForm on static and instance APIs.
  • Includes query in headers flattening, defaults init, and content-type handling.
  • Updates TypeScript types in index.d.ts and index.d.cts with 'query' | 'QUERY' and new methods.
  • Works with axios({ method: 'query' }); no breaking changes.
  • Docs: add API reference and examples for query/queryForm. Closes Add the QUERY HTTP method #5465.

Testing

  • Added tests/unit/core/query-method.test.js for JSON body, queryForm multipart, content-type defaults, and generic config path.
  • Updated tests/unit/api.test.js to check query and queryForm exist on static and instance APIs.
  • All existing tests pass locally.

Written for commit 8ed320c. Summary will update on new commits.

Add axios.query() and axios.queryForm() as shorthand methods for the
QUERY HTTP method (RFC draft-ietf-httpbis-safe-method-w-body).

QUERY is a safe, idempotent method like GET but allows a request body,
making it ideal for complex queries that don't fit in URL parameters.

Changes:
- Add query to the methods-with-data alias group (like post/put/patch)
- Add query to default headers initialization
- Add query to the headers flattening list
- Add query to the content-type dispatch list
- Update TypeScript declarations (both ESM and CJS)
- Add tests for query/queryForm with body, content-type, and form data

Closes axios#5465
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 7 files

Confidence score: 3/5

  • There is a concrete regression risk in index.d.cts: HeadersDefaults is missing query, which creates a type/runtime mismatch for the new QUERY default headers.
  • Because this is a medium-severity (6/10), high-confidence (9/10) issue in shared type definitions, it can impact consumers at compile time and lead to confusing behavior versus runtime defaults.
  • This should be straightforward to fix, but it is worth addressing before merge to keep typings aligned with actual header behavior.
  • Pay close attention to index.d.cts - ensure HeadersDefaults includes query so declared types match runtime QUERY defaults.
Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="index.d.cts">

<violation number="1" location="index.d.cts:378">
P2: `HeadersDefaults` is missing `query`, causing a type/runtime mismatch for newly added QUERY default headers.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Comment thread index.d.cts
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot Mar 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: HeadersDefaults is missing query, causing a type/runtime mismatch for newly added QUERY default headers.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At index.d.cts, line 378:

<comment>`HeadersDefaults` is missing `query`, causing a type/runtime mismatch for newly added QUERY default headers.</comment>

<file context>
@@ -364,7 +374,9 @@ declare namespace axios {
     | 'unlink'
-    | 'UNLINK';
+    | 'UNLINK'
+    | 'query'
+    | 'QUERY';
 
</file context>
Fix with Cubic

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mahmoodhamdi, can you please check this? We would need to fix this issue as it is valid.

@jasonsaayman jasonsaayman added priority::medium A medium priority commit::feat The PR is related to a feature labels Apr 4, 2026
Copy link
Copy Markdown
Member

@jasonsaayman jasonsaayman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix the cubic issue raised. This is a valid concern.

@jasonsaayman jasonsaayman added the status::changes-requested A reviewer requested changes to the PR label Apr 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

commit::feat The PR is related to a feature priority::medium A medium priority status::changes-requested A reviewer requested changes to the PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add the QUERY HTTP method

2 participants