Query Parameter Manipulation API: The Complete Guide

Need to parse, modify, or build URL query strings? This guide covers everything about query parameter manipulation via API, including parsing complex query strings, adding/removing parameters, and implementation examples.

Understanding Query Strings

A query string is the part of a URL after the ? symbol, containing key-value pairs separated by &. For example:

https://example.com/search?q=hello&page=1&limit=10

Query strings can have complex scenarios:

  • Multiple values for the same key: ?color=red&color=blue
  • Encoded characters: ?name=John%20Doe
  • Empty values: ?flag&name=test

Available Operations

Parse

Extract query parameters into a structured object.

Add/Set

Add new parameters or update existing ones.

Remove

Delete specific parameters from the query string.

Build

Construct a query string from an object of parameters.

Tip: The API handles encoding/decoding automatically, so you can work with plain text values.

Using the Query Params API

TinyFn provides comprehensive query parameter operations:

API Request - Parse
POST https://api.tinyfn.io/v1/url/query-params
Headers: X-API-Key: your-api-key
Content-Type: application/json

{
  "operation": "parse",
  "url": "https://example.com/search?q=hello&page=1&tags=a&tags=b"
}
Response
{
  "params": {
    "q": "hello",
    "page": "1",
    "tags": ["a", "b"]
  },
  "query_string": "q=hello&page=1&tags=a&tags=b",
  "param_count": 3
}
API Request - Modify
{
  "operation": "modify",
  "url": "https://example.com/search?q=hello&page=1",
  "add": {"limit": "20", "sort": "date"},
  "remove": ["page"]
}

Parameters

Parameter Type Description
operation string "parse", "modify", or "build" (required)
url string URL to parse or modify
add object Parameters to add (for modify)
remove array Parameter names to remove (for modify)
params object Parameters to build (for build operation)

Code Examples

JavaScript / Node.js

const response = await fetch(
  'https://api.tinyfn.io/v1/url/query-params',
  {
    method: 'POST',
    headers: {
      'X-API-Key': 'your-api-key',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      operation: 'modify',
      url: 'https://example.com?page=1',
      add: { limit: '20', sort: 'date' },
      remove: ['page']
    })
  }
);
const { result } = await response.json();
console.log(result); // "https://example.com?limit=20&sort=date"

Python

import requests

response = requests.post(
    'https://api.tinyfn.io/v1/url/query-params',
    headers={'X-API-Key': 'your-api-key'},
    json={
        'operation': 'parse',
        'url': 'https://example.com?q=hello&page=1'
    }
)
params = response.json()['params']
print(params)  # {'q': 'hello', 'page': '1'}

cURL

curl -X POST "https://api.tinyfn.io/v1/url/query-params" \
  -H "X-API-Key: your-api-key" \
  -H "Content-Type: application/json" \
  -d '{"operation": "parse", "url": "https://example.com?q=hello"}'

Common Use Cases

  • URL Modification: Add tracking parameters to links
  • Form Processing: Parse form submissions sent as query strings
  • API Integrations: Build query strings for external API calls
  • Analytics: Extract and analyze URL parameters
  • Deep Linking: Parse and handle deep link parameters

Best Practices

  1. Handle arrays: Some parameters may have multiple values
  2. Encode properly: Let the API handle encoding special characters
  3. Validate values: Sanitize parameter values before using them
  4. Preserve order: If order matters, use the sorted option carefully

Try the Query Params API

Get your free API key and start manipulating query parameters in seconds.

Get Free API Key

Ready to try TinyFn?

Get your free API key and start building in minutes.

Get Free API Key