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
| val nativeList = JsArray(JsInt(1), JsInt(2), JsInt(3)).as[List[Int]] | |
| val failedConversion = JsArray(JsString("not"), JsString("ints")).as[List[Int]] |
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
| import com.plasmaconduit.json._ | |
| val verbose = JsObject( | |
| "key1" -> JsString("value"), | |
| "key2" -> JsInt(42), | |
| "key3" -> JsBoolean(true), | |
| "key4" -> JsArray(JsInt(3), JsBoolean(true)) | |
| ) | |
| val sugar = JsObject( |
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
| import com.plasmaconduit.json._ | |
| val result = JsonParser.parse("""{"key1": "value", "key2": true}""") |
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
| final case class JsonController() extends Controller { | |
| def action(implicit request: HttpRequest): Box[Throwable, HttpResponse] = { | |
| Ok(JsObject( | |
| "status" -> "ok", | |
| "message" -> JsObject( | |
| "email" -> "users@gmail.com", | |
| "admin" -> false | |
| ) | |
| )) |
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
| val server = PlasmaConduit( | |
| port = 3000, | |
| middleware = List(SessionMiddleware(JWTSessionHandler(JWTSha256, "topsykretz"))), | |
| defaultRoute = MissingController(), | |
| routes = HttpRoutes( | |
| HttpGetMethodRoutes( | |
| HttpPathRoute("/", RootController()), | |
| ) | |
| ) | |
| ) |
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
| final case class SessionVisitsController() extends Controller { | |
| def action(implicit request: HttpRequest) = { | |
| val visits = request.session.get("visits").getOrElse("0").toLong | |
| Ok(s"This is so cool, you've viewed it $visits times!") | |
| .withSession(request.session.set("visits", (visits + 1).toString)) | |
| } | |
| } |
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
| final case class AuthenticatedOnlyMiddleware() extends Middleware { | |
| def intercept(next: Controller) = AdhocController { request => | |
| request | |
| .session | |
| .get("user") | |
| .map(_ => next.action(request)) | |
| .getOrElse(Found("").withHeader(Location("/login"))) | |
| } | |
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
| final case class IdentityMiddleware() extends Middleware { | |
| def intercept(next: Controller) = AdhocController { request => | |
| next.action(request) | |
| } | |
| } |
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
| final case class ExampleController() extends Controller { | |
| def middleware = Seq(LoggingMiddleware(), CacheMiddleware()) | |
| def action(implicit request: HttpRequest) = Ok("Hello") | |
| } |
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
| final case class SimpleController() extends Controller { | |
| def action(implicit request: HttpRequest) = { | |
| Found("").withHeader(Location("/login")) | |
| } | |
| } |
NewerOlder