liveBook · Manning

Path variable

A path variable is a named value embedded in a request URL path and made available to the handler processing that request.

How 3 Manning books explain it

Go in Practice, Second Edition

A path variable is a named value captured from a matched URL path and made available to the request handler.

How it is used
Routes requests containing URL-path identifiers to handlers that need those values.
How deep it goes
Works through route registration, value extraction, integer conversion, and response checks; does not develop advanced router internals.
Examples
Demonstrates `GET /comments/{id}` for comment lookup and `GET /goodbye/{name}` for a named greeting response.
What you can do after
Apply it via Go’s ServeMux and Request.PathValue to read a named path segment in an HTTP handler.

Read how Go in Practice, Second Edition explains path variable →

Spring Start Here, Second Edition

A path variable is a value conveyed within a request path, typically as a variable segment of a resource URI.

How it is used
Carries a small, mandatory client value in the request path for a controller to use.
How deep it goes
Defines positional path values and demonstrates curly-brace mappings with @PathVariable, while limiting advice to small numbers of values.
Examples
Demonstrates a /home/{color} route that captures values such as blue, red, and green.
What you can do after
Apply Spring MVC’s @PathVariable to bind a mandatory path segment to a controller parameter.

Read how Spring Start Here, Second Edition explains path variable →

Spring in Action, Sixth Edition

A path variable is a value embedded in a URL path and bound to a controller method parameter.

How it is used
Retrieves one REST resource by binding a URL path value to a controller method parameter.
How deep it goes
Explains placeholders, parameter binding, repository lookup, Optional results, and explicit 404 handling.
Examples
Uses a taco endpoint that maps /api/tacos/{id} to a repository lookup by Long ID.
What you can do after
Apply it via Spring REST annotations to retrieve an identified resource and return an appropriate success or not-found response.

Read how Spring in Action, Sixth Edition explains path variable →

What to know first

Related concepts

Questions about path variable

What is path variable?

A path variable is a named value embedded in a request URL path and made available to the handler processing that request.

Which Manning books explain path variable?

Go in Practice, Second Edition, Spring Start Here, Second Edition and Spring in Action, Sixth Edition.

What should I know before learning path variable?

Manning books that teach path variable usually introduce uri first.

What is the difference between path variable and HTTP request parameter?

A path variable is a named value embedded in a request URL path and made available to the handler processing that request. An HTTP request parameter is a named value supplied with an HTTP request, commonly through its query string or submitted form data.

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.