Showing posts with label play framework. Show all posts
Showing posts with label play framework. Show all posts

What is scala twirl

Twirl is play framework scala based template engine.
https://github.com/spray/twirl

Integrate swagger with Play Framework link /practice in progress

http://swagger.io/playing-with-swagger-using-swagger-and-swagger-ui-with-the-play-framework/

i just read it, yet to check and practice in full

build.sbt
----
"com.wordnik" %% "swagger-play2" % "1.3.12" exclude("org.reflections", "reflections"), "org.reflections" % "reflections" % "0.9.8" notTransitive (), "org.webjars" % "swagger-ui" % "2.1.8-M1"

application.conf :
----
api.version="1.0" swagger.api.basepath="http://localhost:9000"

routes
----
GET / controllers.Assets.at(path="/public", file="index.html")

GET /api-docs controllers.ApiHelpController.getResources

POST /login controllers.SecurityController.login() POST /logout controllers.SecurityController.logout()

GET /api-docs/api/todos controllers.ApiHelpController.getResource(path = "/api/todos")
GET /todos controllers.TodoController.getAllTodos()
POST /todos controllers.TodoController.createTodo()


swagger annotation
--------
@Api(value = "/api/todos", description = "Operations with Todos") @Security.Authenticated(Secured.class)
public class TodoController extends Controller {


@ApiOperation(value = "get All Todos",
     notes = "Returns List of all Todos",
     response = Todo.class,
     httpMethod = "GET")
public static Result getAllTodos() {
     return ok(toJson(models.Todo.findByUser(SecurityController.getUser())));
}
@ApiOperation(
     nickname = "createTodo",
     value = "Create Todo",
     notes = "Create Todo record",
     httpMethod = "POST",
     response = Todo.class
 )
@ApiImplicitParams(
     {
          @ApiImplicitParam(
               name = "body",
               dataType = "Todo",
               required = true,
               paramType = "body",
               value = "Todo"
          )
     }
)
@ApiResponses(
          value = {
                  @com.wordnik.swagger.annotations.ApiResponse(code = 400, message = "Json Processing Exception")
          }
)
public static Result createTodo() {
     Form form = Form.form(models.Todo.class).bindFromRequest(); 
     if (form.hasErrors()) {
         return badRequest(form.errorsAsJson());
     }
     else {
          models.Todo todo = form.get();
          todo.user = SecurityController.getUser();
          todo.save();
          return ok(toJson(todo));
     }
}


AWS ec2 selection decision for Play Framework 2.4

Amazon Linux/Ubuntu/Cent OS
not decide, even the below discussion is for creating binary distribution of package
Reference:

activator clean compile dist

use nginx as front load balancer for port forwarding from 80 to 9000

old reference might not work exactly
SCRIPT: /al-start.sh
chmod +x start
nohup ./start -server -Dconfig.resource=application-prod.conf -Dhttp.port=9000 &
A few notes about this script:
  1. I created this script so I don’t have to edit the Play start script.
  2. It uses a Play configuration file named application-prod.conf. That file just needs to be on the classpath, so having it in the Play application conf folder is all you need.
  3. It runs the server on port 9000. You don’t need to specify that on the command line, but I have a bad memory, so if I want to change this later, it’s easiest to specify it now.
Another note about the production environment: Port 80 on the kbhr.co website is served by Nginx, and it does a proxy to serve the Play application.