Skip to content

Instantly share code, notes, and snippets.

@jaydonnell
Created June 23, 2011 19:54
Show Gist options
  • Save jaydonnell/1043474 to your computer and use it in GitHub Desktop.
Save jaydonnell/1043474 to your computer and use it in GitHub Desktop.
scala, clojure comparison
(defn admin-only [handler]
(fn [request]
(when (:admin (:session request))
(handler request))))
(defroutes admin-routes
(GET "/some-admin-only-page" (admin-page))
(GET "/another-admin-only-page" (other-admin-page)))
(defroutes admin-form-routes
(POST "/some-admin-only-page" (mangle-database)))
(decorate admin-routes with-layout admin-only with-session)
(decorate admin-form-routes admin-only with-session)
(defroutes all-routes
admin-routes
admin-form-routes
other-routes
etc.)
trait EmailServices extends BlueEyesServiceBuilder {
val emailService = service("email", "1.32") { context =>
startup {
loadContactList(context.config("contactFile"))
} ->
request { contactList =>
path("/emails/") {
contentType(application/json) {
get { request =>
...
HttpResponse(content = Some(JArray(emailIds)))
} ~
post { request =>
...
HttpResponse(status = OK)
} ~
path('emailId) {
get { request =>
val emailId = request.parameters('emailId)
...
HttpResponse(content = Some(emailObj))
}
}
}
}
} ->
shutdown { contactList =>
contactList.finalize
}
}
}
object EmailServer extends BlueEyesServer with EmailServices
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment