db3.aiVisit main site

22 October 2026

What Are Params? A TypeScript Guide to Function, Route, and Query Parameters

TL;DR

Params is short for parameters, but the surrounding code decides what it means. In a function, parameters are named inputs and arguments are the values you pass. In a URL, a route parameter occupies a variable path segment; a query parameter follows ?. Neither a TypeScript type nor a readable URL validates incoming data. Check values at the application boundary before using them.

Table of contents

What does “params” mean here?

If you see params without context, look at where the value came from. Is it declared in a function signature, extracted from a route, read from a URL query string, or passed as model configuration? These are related ideas, not one shared JavaScript object. MDN distinguishes function parameters from the arguments supplied to them; Fastify gives route matches a request.params property.

Where you see it What it usually means Quick clue
function load(id: string) A named function parameter Declared between the function's parentheses
load('r-42') An argument, not a parameter declaration Supplied at the call site
Route /api/reports/:id A path or route parameter Named by a variable segment of the route pattern
URL ?limit=10 A query or search parameter Appears after ? in the URL
URLSearchParams A standard interface for query entries Read through a URL's searchParams
AI model documentation Learned model values or configuration, depending on context Appears in training, model-size, or inference material

Scope: This guide covers TypeScript function and web-request terminology first. It does not claim that every framework uses params for the same request property. For instance, Next.js useParams() returns dynamic route segments, whereas a URL's searchParams accesses its query. When the property name is ambiguous, inspect the specific framework's documentation rather than treating those APIs as interchangeable.

Function parameters versus arguments in TypeScript

A parameter is a name in the function definition. An argument is a value supplied during a call. In formatLabel('Q4'), name below is the parameter and 'Q4' is the argument. TypeScript checks calls against the declared types, but a remote HTTP client never runs your TypeScript compiler. The TypeScript handbook describes required, optional, default, and rest parameters.

function formatLabel(name: string, suffix = 'report'): string {
  return `${name} ${suffix}`;
}

function findReport(id: string, region?: string): string {
  return region ? `${region}/${id}` : id;
}

function joinTags(...tags: string[]): string {
  return tags.join(', ');
}

formatLabel('Q4');                 // uses the default suffix
formatLabel('Q4', 'summary');      // overrides the default
findReport('r-42');               // region is undefined
findReport('r-42', 'west');       // supplies an optional value
joinTags('finance', 'internal');  // rest values form an array

The name and id parameters are required at a typed call site. region? can be omitted, suffix receives a default if omitted or passed undefined, and ...tags gathers zero or more arguments. These examples are ordinary TypeScript, not db3.ai route APIs. A generic such as function first<T>(items: T[]): T | undefined introduces a type parameter T, which describes a relationship between types rather than carrying an HTTP value. See the TypeScript guide to type parameters.

Diagram of argument values flowing into required, optional, default, and rest function parameters

When you inspect unfamiliar code, start at the declaration and then find its callers. A variable named params passed to buildReport(params) might be a plain application object; its name alone cannot tell you whether it contains a route match or a query string. Check its type, construction, and the point where untrusted input first entered the program.

URL params: path, query, headers, and body

For GET /api/reports/weekly?limit=10, weekly is the path parameter when the route is registered as /api/reports/:reportId. limit=10 is a query parameter. The ? starts the query string and & separates additional entries. A URL can contain repeated query keys, such as ?tag=finance&tag=internal; decide whether your endpoint accepts one value, many values, or rejects duplicates. Fastify documents colon-prefixed dynamic route segments, and MDN documents URLSearchParams.getAll() for repeated keys.

Input location Example Typical job Read at the boundary
Path segment /api/reports/weekly Identify a particular report Matched route parameter
Query string ?limit=10 Select a page size or filter Query parser or URLSearchParams
Header Authorization Convey credential material for verification Request headers
Body JSON { "title": "Draft" } Propose data for a create or update Configured body parser

Diagram distinguishing URL path, query, headers, and request body as four separate inputs to an application

These locations are not interchangeable. A path identifier does not grant access to the identified record, and a query setting should not be trusted merely because it appears in a bookmarkable URL. A request body is separate from both; it needs the appropriate parser before the handler can inspect its fields. Fastify's request reference lists params, query, headers, and body separately. For the body-specific parsing sequence, see our bodyparser explanation.

There is also a useful distinction between query parameters in a URL and function parameters inside a handler. A handler can pass a validated limit from the query into a function's limit parameter. Those are two stages of the same feature, not two names for the same trust boundary. A TypeScript annotation on the handler's input describes developer expectations; it does not transform ?limit=10 into a safe integer.

A small db3.ai example: move a URL value into typed application logic

I would keep a URL parsing example intentionally small: accept a report ID in the path and an optional page-size limit in the query, validate both, then pass a selected object to application code. This is a read-only preview that returns the chosen inputs. It does not fetch a report or implement authentication. We use Fastify for routing and db3.ai's documented validate() for checking application values; db3.ai does not implicitly create this endpoint. Our first HTTP app walkthrough shows the Fastify integration, and the db3.ai validation reference specifies the import, rule names, and result shape.

Setup: In an existing TypeScript ESM application, follow the db3.ai installation guide for matching preview App and Pure packages and Fastify 5. Its walkthrough specifies Node.js 24 or newer and explains that the preview packages require matching maintainer-supplied tarballs rather than an assumed public npm install. Register the following function on your application's existing Fastify instance during startup. Application boot, listener lifecycle, routing policy, authentication, and persistence remain yours to provide. The App lifecycle guide explains why an App should not be constructed per request.

import type { FastifyInstance } from 'fastify';
import { validate } from '@db3.ai/app/validation';

function reportPreview(input: { reportId: string; limit: number }) {
  // Application-owned read-only projection, not a database lookup.
  return { reportId: input.reportId, pageSize: input.limit };
}

export function addReportPreviewRoute(server: FastifyInstance): void {
  server.get<{ Params: { reportId: string } }>(
    '/api/reports/:reportId',
    async (request, reply) => {
      // This base only permits parsing a relative request URL.
      const url = new URL(request.url, 'http://local.invalid');
      const limits = url.searchParams.getAll('limit');
      if (limits.length > 1) {
        return reply.code(400).send({ message: 'Supply limit once.' });
      }

      const limitText = limits[0] ?? '20';
      if (!/^(?:[1-9]|[1-4][0-9]|50)$/.test(limitText)) {
        return reply.code(400).send({ message: 'Use a limit from 1 to 50.' });
      }

      const checked = validate(
        { reportId: request.params.reportId, limit: Number(limitText) },
        {
          reportId: [
            'required', 'string',
            { rule: 'regex', pattern: /^[a-z0-9-]{1,64}$/ },
          ],
          limit: ['required', 'integer', 'min:1', 'max:50'],
        },
      );
      if (!checked.valid) {
        return reply.code(400).send({ message: 'Invalid report selection.' });
      }

      const input = {
        reportId: String(checked.data.reportId),
        limit: Number(checked.data.limit),
      };
      return reportPreview(input);
    },
  );
}

After registration, /api/reports/weekly?limit=10 is intended to return { "reportId": "weekly", "pageSize": 10 }; omitting limit selects 20. A duplicate limit, zero, or a nonnumeric value is intended to return 400. These are example expectations, not a claim that this article's code was executed. The route allows unrelated query keys but ignores them; reject unknown keys too if your public contract calls for that. http://local.invalid is a parsing base, not the application's public origin, redirect target, or db3.ai canonical URL generator.

Why check twice? The query regex defines a deliberately narrow decimal representation, then validate() checks the chosen number and path ID. The db3.ai validation guide warns that validated data is the original object, not a sanitized or converted DTO. We explicitly build the object passed to reportPreview() and send controlled errors rather than returning raw validation failures, which may include submitted values. Before using a real report ID for a private lookup, verify the caller and enforce ownership or tenant authorization in the data access path. Add HTTP tests for valid, missing, duplicate, and malformed inputs and cross-user access to any eventual private report; this preview alone proves none of those production behaviors.

How to identify params in an unfamiliar codebase

Follow the value, not the variable name:

  1. Find the declaration. A function signature tells you its expected parameters and types. Find the call site to see the arguments actually supplied.
  2. Read the route pattern. A dynamic segment such as :reportId often becomes a route match; check the adapter's exact params contract. A framework hook may expose only path matches.
  3. Inspect the query parser. Check whether code reads request.query, a URL object, or another parser. Ask what happens with absent, blank, or repeated keys.
  4. Locate runtime checks. Types and casts do not establish that remote input matches a contract. Find the validation, normalization, authentication, and authorization steps before the value reaches a database or a job.

If a value changes shape between those steps, name the transition: raw query text, checked integer, then a typed application input. This is especially important where a number-like string such as "10" must become a number. db3.ai's validator can accept some numeric strings without converting the returned data; conversion is an explicit application choice.

What are params in AI models?

Here context matters even more. Model parameters can mean learned weights and biases adjusted during training; Google's machine-learning course demonstrates that meaning in gradient descent. Other discussions use “parameters” for training or inference settings. A model's learned weights are not the same thing as the limit query parameter in an HTTP URL or the inputs in a TypeScript function signature. If an AI API example uses params, identify whether it names model settings, a tool's input object, or ordinary HTTP request data before choosing how to type and validate it.

Frequently asked questions

What are params in a URL?

They are values associated with a URL. A path param fills a variable route segment, such as weekly in /reports/weekly when the pattern is /reports/:reportId. A query param is an entry after ?, such as limit=10. Fastify's route documentation and MDN's URL query reference show the two different access paths.

Why do we use params?

Parameters let a function accept inputs without hard-coding them. URL parameters let a route select a resource or a request supply options such as filtering. Their usefulness depends on a clear contract: document whether a value is required, how it is parsed, and which runtime checks and permissions apply before acting on it.

Are params and searchParams the same?

Not necessarily. URL.searchParams specifically represents the query string. In Fastify, request.params holds values matched from the route, while request.query is its parsed query string. See MDN's URL.searchParams definition and Fastify's request fields.

What are params in AI models?

In a training context, they may be the model's learned weights and biases. In an API call, the word may instead refer to configurable inputs. Read the surrounding model or API documentation to tell which meaning applies. Google's training example explains learned weights and biases.

For a working next step, adapt the read-only preview to your own route contract, then follow the db3.ai validation walkthrough for the exact rule behavior and the public API reference when you need signature-level detail. Keep authorization separate from terminology: understanding where a reportId came from is the beginning of a safe lookup, not permission to return the record.

Sources