Axios Params vs Data: What Is the Difference?

When making HTTP requests using Axios, configuring how you send information to the server is crucial for API communication. Two of the most common configuration options are params and data. While both are used to pass information to an endpoint, they function in completely different ways, attach data to different parts of the HTTP request, and are intended for distinct HTTP methods. This guide outlines the core differences, use cases, and syntax for both options.

What is params in Axios?

The params property is used to send URL query parameters. When you specify params, Axios serializes the key-value pairs and appends them to the end of the request URL following a question mark (?).

Key Characteristics of params:

Example Using params:

axios.get('/api/products', {
  params: {
    category: 'electronics',
    sort: 'price_asc'
  }
});
// Resulting Request: GET /api/products?category=electronics&sort=price_asc

What is data in Axios?

The data property is used to send a request body payload. Instead of modifying the URL, Axios packages this information inside the body of the HTTP request.

Key Characteristics of data:

Example Using data:

axios.post('/api/products', {
  name: 'Wireless Headphones',
  price: 99.99,
  inStock: true
});
// Resulting Request: POST /api/products
// Request Body: {"name":"Wireless Headphones","price":99.99,"inStock":true}

Summary of Differences

Feature params data
Location URL Query String (?key=value) HTTP Request Body
Primary HTTP Methods GET, DELETE, HEAD POST, PUT, PATCH
Content-Type Header Not applicable Typically application/json or multipart/form-data
Size Limit Restricted by URL length limits (~2,048 characters) Determined by server-configured payload limits (often megabytes)
Data Structure Flat key-value pairs Complex objects, arrays, files, and text
Security Low (exposed in logs, history, and URL) Higher (hidden in payload, though HTTPS is still required)

Choosing the Right Option