Created
June 23, 2011 19:54
-
-
Save jaydonnell/1043474 to your computer and use it in GitHub Desktop.
scala, clojure comparison
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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.) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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