

You’re responsible for validating the input to make sure it makes sense in that context. Just like with wildcard routes, the parameter is not decoded by the router or encoded by the reverse router. You can also define your own regular expression for the dynamic part, using the $id syntax: GET /items/$id (id: Long) §Dynamic parts with custom regular expressions The reverse router simply does a string concatenation, so you will need to make sure the resulting path is valid, and does not, for example, contain multiple leading slashes or non-ASCII characters. It is your responsibility to validate the raw URI segment as you would for any user input. Note that dynamic parts spanning several / are not decoded by the router or encoded by the reverse router. Here for a request like GET /files/images/logo.png, the name dynamic part will capture the images/logo.png value. * regular expression: GET /files/*name (name) If you want a dynamic part to capture more than one URI path segment, separated by forward slashes, you can define a dynamic part using the *id syntax, also known as a wildcard pattern, which uses the. Unlike other pattern types, path segments are automatically URI-decoded in the route, before being passed to your controller, and encoded in the reverse route. The default matching strategy for a dynamic part is defined by the regular expression +, meaning that any dynamic part defined as :id will match exactly one URI path segment. Note: A URI pattern may have more than one dynamic part. If you want to define a route that retrieves a client by ID, you’ll need to add a dynamic part: GET /clients/:id (id: Long)

§Static pathįor example, to exactly match incoming GET /clients/all requests, you can define this route: GET /clients/all () §Dynamic parts Parts of the request path can be dynamic. The URI pattern defines the route’s request path. The HTTP method can be any of the valid methods supported by HTTP ( GET, PATCH, POST, PUT, DELETE, HEAD). One such modifier is the “nocsrf” modifier to bypass the CSRF filter: + nocsrf This can change the behavior of certain Play components. It is also possible to apply modifiers by preceding the route with a line starting with a +. This is especially useful when combined with String Interpolating Routing DSL also known as SIRD routing, or when working with sub projects that route using several routes files. You can tell the routes file to use a different router under a specific prefix by using “->” followed by the given prefix: -> /api api.MyRouter You can also add comments to the route file, with the # character. Let’s see what a route definition looks like: GET /clients/:id (id: Long)Įach route starts with the HTTP method, followed by the URI pattern. Each route consists of an HTTP method and URI pattern, both associated with a call to an Action generator. This file lists all of the routes needed by the application. §The routes file syntaxĬonf/routes is the configuration file used by the router. If you wish to use your own static state you can still do so in a controller that is a class. That is no longer supported, as Play no longer relies on static state.
Scala uuid generator generator#
That means the class is suitable for use with dependency injection and can also be instantiated manually using the constructor.īefore Play 2.7.0, Play supported a static routes generator that allowed defining controllers as objects instead of classes. Play’s default routes generator creates a router class that accepts controller instances in an constructor. This means that you’ll see route errors directly in your browser: Routes are defined in the conf/routes file, which is compiled. clients/1542, /photos/list), including the query string This event contains two major pieces of information: The router is the component in charge of translating each incoming HTTP request to an Action.Īn HTTP request is seen as an event by the MVC framework. English ▾ English българин Français 日本語 Türkçe HTTP programming
