Node.js › HTTP & Web Servers
What is the difference between an HTTP request header and a query parameter, and when should each be used to pass information to a Node.js server?
BeginnerAnswer
Headers carry metadata about the request itself (authentication tokens, content type, accepted formats) that's generally not part of the actual resource being requested, while query parameters are part of the URL and typically represent filtering, sorting, or pagination options for the specific resource being requested -- a general convention is that headers carry cross-cutting concerns applicable across many different endpoints, while query parameters carry endpoint-specific data relevant to that particular request.
// Header: cross-cutting concern (auth), same pattern across many endpoints
fetch('/api/orders', { headers: { Authorization: 'Bearer token123' } });
// Query parameters: specific to this endpoint's filtering/pagination needs
fetch('/api/orders?status=shipped&page=2&limit=20');Real-world example An API consistently uses an Authorization header for authentication across every single endpoint (since it's a cross-cutting concern), while using endpoint-specific query parameters like ?status=shipped for filtering results, following a clear, predictable convention rather than mixing the two purposes inconsistently.