Skip to content

Route

A route is the mapping between a URL pattern and the code that handles it: a regex or template like `/users/{id}` that a framework matches against incoming requests to dispatch them to a controller or function.

Definition

What it is

Routes come in two flavours. Static routes match an exact path (/about, /contact). Dynamic routes use patterns with parameters (/users/{id}, /posts/{slug}) and extract values. A router is the component that takes an incoming request and selects the matching route by comparing method + path.

In server-rendered frameworks (Laravel, Rails, Django), routes live in dedicated files (routes/web.php, config/routes.rb, urls.py). In file-based frameworks (Next.js, EIK CMS, Hugo), the file path is the route. In a REST API, routes may be auto-derived from resources.

Why it matters

Routing errors are the most common cause of "it works locally, 404 in production" — different configs, different orderings. A route evaluated 20 times per request (because the router iterates the whole list) is a hidden latency source. A route that matches too loosely (/{path}/*) can shadow protected routes.

Static vs dynamic vs file-based

Type

Example

Framework

Static

GET /about

All

Dynamic

GET /users/{id}

Express, Laravel, Rails

Regex

GET /posts/[0-9]+

Framework-specific

File-based

content/en/about/article.yaml

EIK CMS, Hugo, Next.js

Resource

resource :users → 7 routes

Rails

The dispatch flow

graph LR
  R[Request] --> RT[Router]
  RT --> M[Match pattern]
  M --> MW[Middleware]
  MW --> H[Handler]
  H --> Resp[Response]
  style RT fill:#E8F5E9

How to design routes well

Routes that age

  1. Nouns, not verbs

    GET /users/42, not GET /getUser?id=42.

  2. HTTP method = action

    GET read, POST create, PUT replace, PATCH update, DELETE remove.

  3. Stable identifiers in path

    Slugs and IDs, not state (/users/current-user-with-name-ana).

  4. Order matters

    Specific routes before generic: /users/me before /users/{id}.

  5. Version the contract

    /v1/users/42 lets you break without breaking clients.

Common failures

Origin

The word comes from Old French rute / Latin rupta via — a cleared road. Network routing (IP routing, 1970s) gave the term its computing sense: choosing the path a packet takes. Web frameworks (Rails, 2004; Express, 2010) adopted it for URL-to-handler mapping.

Routing is the process of selecting a path for traffic in a network or between or across multiple networks.

— RFC 791, *Internet Protocol*, 1981 (paraphrase)
1970s · routing en redes
2004 · Rails introduce DSL de rutas
2010 · Express populariza en JS
2016 · Next.js file-based routing

Evidence

FAQ

Route vs path?

Path is the URL part; route is the (method + pattern + handler) triple.

File-based vs config-based?

File-based is convention-over-config (Next.js, Hugo); config-based is explicit (Express, Rails).

When to use wildcards?

Only for intentional catch-alls (/admin/{path*}), never as default.

How many routes max?

No hard limit; keep it under 500 for maintainability.

Connections

Etymology

Origin: borrowed

  • route (noun): from Latin rupta via, "broken way"

Semantic network

RoutewebEndpointrouterMiddlewarecontroller

● broader ● narrower ● related

Broader

  • web

Related

Used in the garden

Sources