Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Play Framework: Arrow ("->") in routing

The Play + Java + CRUD Activator has the following route file, and I don't understand what -> does in it.

# Routes
# This file defines all application routes (Higher priority routes first)
# ~~~~

# Home page
# Home page
GET     /               controllers.Application.index()
# CRUD Controllers and REST API
->     /                play.crud.Routes
like image 326
Alan C. Avatar asked Jun 23 '15 17:06

Alan C.


People also ask

In which folder does play expect routes file?

The answer to this question lies in the app/conf/routes configuration file. Play's router translates HTTP requests into action calls.

What is play framework in Scala?

Play Framework makes it easy to build web applications with Java & Scala. Play is based on a lightweight, stateless, web-friendly architecture. Built on Akka, Play provides predictable and minimal resource consumption (CPU, memory, threads) for highly-scalable applications.

What is routing in Java?

A Router is an actor that routes incoming messages to outbound actors. The router routes the messages sent to it to its underlying actors called 'routees'.

Is Play Framework open source?

Play Framework is an open-source web application framework which follows the model–view–controller (MVC) architectural pattern. It is written in Scala and usable from other programming languages that are compiled to JVM bytecode, e.g. Java.


1 Answers

In my opinion, the Play documentation for this is poor. I will explain based on a nice sample on Github.

In conf/routes you may have:

->         /admin                admin.Routes
->         /customer             customer.Routes
->         /common               common.Routes

then, for example, admin.Routes, you can resolve as follows:

Look for the definition for admin which is in Build.sbt:

// Admin Portal
lazy val admin = project.in(file("modules/admin"))
  .dependsOn(common)

You see that it's in modules/admin. Head over to modules/admin/conf/routes where you'll see more routes:

GET        /index               controllers.admin.Application.getIndex()

So, Play puts that together with the original path /admin becoming /admin/index. That is, if you bring up /admin/index in the browser, controllers.admin.Application.getIndex() will be used to serve this route.

like image 85
bjfletcher Avatar answered Sep 21 '22 06:09

bjfletcher