Name |
Deprecated : see io.cayla.web |
---|---|
Backends | JVM |
Maven coordinates | |
Compatible Ceylon release |
JVM: 1.0.0 (outdated) |
Published | Nov 30, 2013 |
Stats |
Downloads (JVM): 484 Source downloads: 451 |
Description |
The Cayla Web FrameworkCayla makes easy creating web application with Ceylon. Creating a simple application in secondsImport the Cayla modulemodule my.app "1.0.0" { import cayla "0.2.3"; } Write the controllerimport cayla { ... } object controllers { route("/") shared class Index() extends Controller() { shared actual default Response handle() => ok().body("Hello World"); } } shared void run() { value application = Application(controllers); application.run(); } Build and run!> ceylon compile my.app ... > ceylon run my.app/1.0 started ApplicationApplications are create via the [[Application]] objects that takes as argument a Ceylon declaration or an object that is scanned to discover the controllers: Package applicationsApplication(`package my.controllers`) Object applicationsApplication(controllers) Application life cycleApplication can be started with [[Application.run]] or [[Application.start]]:
Application configurationConfiguration is handled by the [[Config]] class. By default the appliation is bound on the 8080 port and on all available interfaces. Explicit config can be provided when the application is created: Application(`package my.controllers`, Config{port = 80;}); ControllersControllers must extend the [[Controller]] interface, they can declare parameters which shall declares the
Query parametersroute("/greeter") shared clas Greeter(String name) extends Controller() { shared actual default Response handle() => ok().body("Hello ``name``"); } Path parametersroute("/greeter/:name") shared clas Greeter(String name) extends Controller() { shared actual default Response handle() => ok().body("Hello ``name``"); } Path parameters can match
Controller URLControllers can be addressed using the redefined [[Controller.string]] method. In a controller the expression
RoutingRouting is declared with the route("/") shared class Index() extends Controller() { ... } Objects wrapping controllers can optionally be annotated with the route("/products") object products { route("/") shared class Index() extends Controller() { ... } route("/cars") shared class Cars() extends Controller() { ... } } Controller logicDuring an invocation Cayla dispatches the request to the [[Controller.handle]] method. This method should implement the controller behavior. It is also possible to override the [[Controller.invoke]] method instead that provides access to the [[RequestContext]] class that exposes Cayla objects. Both methods returns a [[Response]] object that is sent to the client via Vert.x ResponsesThe [[Response]] class is the base response, the [[Status]] class extends the response class to define the http status and the [[Body]] class extends the [[Status]] with a response body. Creating responses is usually done via the fluent API and the top level functions such as return notFound().body("Not found!!!!"); Http methodsBy default a controller is bound to a route for all Http methods. This can be restricted by using annotations like
get route("/greeter") shared clas Greeter(String name) extends Controller() { shared actual default Response handle() => ok().body("Hello ``name``"); } |
Dependencies |
ceylon.net/1.0.0
shared
java.base/7 JDK
shared
vietj.vertx/0.3.4
shared
|
Usage |
import cayla "0.2.3"; |
Module links |
Members Imported By Home Code repository Issue tracker Browse Download .car No .js archive Download source archive Download module documentation View API documentation |