Skip to content

Instantly share code, notes, and snippets.

@capotej
Created May 7, 2012 06:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save capotej/2626200 to your computer and use it in GitHub Desktop.
Save capotej/2626200 to your computer and use it in GitHub Desktop.
A simple blog in finatra
package com.posterous.finatrablog
import com.posterous.finatra.{FinatraApp, FinatraServer}
object App {
class Blog extends FinatraApp {
case class Post(var title:String, var body:String)
var posts = List[Post]()
get("/") { request =>
render(path="index.mustache", exports=this)
}
get("/post/new") { request =>
render(path="new.mustache")
}
post("/post/create") { request =>
val title = request.params.get("title").getOrElse("untitled")
val body = request.params.get("body").getOrElse("body")
posts = posts ::: List(new Post(title, body))
redirect("/")
}
}
def main(args: Array[String]) {
val blog = new Blog
FinatraServer.register(blog)
FinatraServer.start()
}
}
<h1>An Blog</h1>
<a href="/post/new">create a post</a>
{{#posts}}
<h3>{{title}}</h3>
<p>{{body}}</p>
<hr>
{{/posts}}
create a post
<form method=post action="/post/create">
<input type="text" name="title"></input><br/>
<textarea width=500 height=500 name="body">
</textarea></br>
<input type="submit" name="create"></input>
</form>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment