Sunday, December 25, 2016

HTTP Routing in Play Framework

We are going to check how Play connect http requests with our code. F.x. when user hits http://localhost:9000/ what happens?

HTTP Routing

There is already built in http router in Play Framework. It allows to connect incoming requests with Play Action and therefore with public method in a controller class.

Configuring HTTP Routing

Normally the configuration for HTTP routing is located in conf/routes. See example:

# Static path
GET   /clients/all                  controllers.Clients.list()
# Dynamic path
GET   /clients/:id         Long)
GET   /files/*name     
# Dynamic parts with regexp
GET   /items/$id<[0-9]+> Long)

If there are few routes are matched for the same request then the first one in a configuration file will be used.

No comments :