Skip to content

Fiber URL Params: Colon vs Asterisk

DodaTech Updated 2026-06-24 1 min read

In this tutorial, you'll learn about Fiber URL Params: Colon vs Asterisk. We cover key concepts, practical examples, and best practices.

Route parameters in Fiber -- Use colon-prefixed :params for path segments and asterisk *params for catch-all routes.

The Problem

Fiber uses Express.js-style routing. :param matches a single path segment, while *param matches everything including slashes.

Wrong

app.Get("/users/:id", func(c *fiber.Ctx) error {
    return c.SendString("User: " + c.Params("id"))
})

Output:

$ curl http://localhost:8080/users/42
User: 42
$ curl http://localhost:8080/users/42/profile
// 404
app.Get("/users/:id", func(c *fiber.Ctx) error {
    return c.SendString("User: " + c.Params("id"))
})
app.Get("/users/:id/*file", func(c *fiber.Ctx) error {
    return c.SendString("User: " + c.Params("id") + ", File: " + c.Params("file"))
})

Output:

$ curl http://localhost:8080/users/42/profile
User: 42, File: profile

Prevention

  • Use :param for single segment matching
  • Use *param for catch-all matching (including slashes)
  • Route order matters: more specific routes first
  • Use c.Params("name") to extract both types
  • Use query params for optional data

Common Mistakes with fiber params

  1. Placing the wildcard pattern first in case expressions, making all subsequent patterns unreachable
  2. Using head and tail instead of pattern matching, causing runtime errors on empty lists
  3. Forgetting that lazy evaluation defers computation until the value is forced, causing space leaks with unevaluated thunks

These mistakes appear frequently in real-world GO code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.

Practice Exercise

Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.

This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.

FAQ

**Can I use regex in Fiber routes?**

Yes. app.Get("/users/:id([0-9]+)", handler).

How do I get all params at once?

Access each with c.Params() individually.

Does Fiber support optional params?

Not directly. Register two routes or use query params.


Built by the developers of Doda Browser, DodaZIP, and Durga Antivirus Pro. DodaTech tutorials help Go developers build production-ready software used by millions.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro