Route Parameters — Clean Language
← All tutorials
web-app5 min

Route Parameters

Route parameters let one endpoint handle many URLs. Define /greet/:name in your route and req.param("name") gives you whatever the visitor typed in that segment. No if-chains, no URL parsing — just declare and read.

Add a colon before a segment name to make it a parameter:

endpoints server:\n    GET "/greet/:name" :\n        string name = req.param("name")\n        string msg = "Hello, " + name + "!"\n        return http.respond(200, "text/plain", msg)
GET /greet/alice  → Hello, alice!\nGET /greet/world  → Hello, world!

req.param("name") reads the :name segment from the URL. The string you pass to req.param must match what you wrote in the route path after the colon.

Parameters are always strings. Convert them when you need a number:

    GET "/items/:id" :\n        string id_str = req.param("id")\n        integer id = id_str.toInteger()\n        string msg = "Loading item " + id.toString() + " of " + (id * 100).toString()\n        return http.respond(200, "text/plain", msg)
GET /items/3  → Loading item 3 of 300

req.param() always returns a string. Call .toInteger() or .toNumber() to convert it for math or comparisons. Use .toString() to convert back when building a response.

Quick recap

  • /path/:segment captures that URL segment as a named parameter
  • req.param("segment") reads the captured value — always returns a string
  • Convert with .toInteger() or .toNumber() when you need arithmetic
  • Multiple parameters work: /posts/:year/:slug uses two req.param() calls
Copied!