blob: f4fab8564d66f60d0be8e3999f36328816841713 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
---
title: "announcing finatra 1.0.0"
date: 2012-11-07T21:20:00Z
comments: true
tags: ["finatra", "scala"]
---
After months of work [Finatra](https://github.com/capotej/finatra#readme) 1.0.0 is finally available! Finatra is a scala web framework inspired by [Sinatra](https://github.com/sinatra/sinatra#readme) built on top of [Finagle](http://twitter.github.com/finagle).
<!--more-->
### The API
The API looks like what you'd expect, here's a simple endpoint that uses route parameters:
```scala
get("/user/:username") { request =>
val username = request.routeParams.getOrElse("username", "default_user")
render.plain("hello " + username).toFuture
}
```
The ```toFuture``` call means that the response is actually a [Future](http://twitter.github.com/scala_school/finagle.html#Future), a powerful concurrency abstraction worth checking out.
Testing it is just as easy:
```scala
"GET /user/foo" should "responsd with hello foo" in {
get("/user/foo")
response.body should equal ("hello foo")
}
```
### A super quick demo
```sh
$ git clone https://github.com/capotej/finatra.git
$ cd finatra
$ ./finatra new com.example.myapp /tmp
```
Now you have an ```/tmp/myapp``` you can use:
```sh
$ cd /tmp/myapp
$ mvn scala:run
```
A simple app should've started up locally on port 7070, verify with:
```sh
$ curl http://locahost:7070
hello world
```
You can see the rest of the endpoints at ```/tmp/myapp/src/main/scala/com/example/myapp/App.scala```
### Heroku integration
The generated apps work in heroku out of the box:
```sh
$ heroku create
$ git init
$ git add .
$ git commit -am 'stuff'
$ git push heroku master
```
Make sure to see the full details in the [README](https://github.com/capotej/finatra#readme) and check out the [example app](https://github.com/capotej/finatra-example).
Props to [@twoism](http://twitter.com/twoism) and [@thisisfranklin](http://twitter.com/thisisfranklin) for their code, feedback and moral support.
|