SlideShare a Scribd company logo
Play Framework
Understanding using Scala
K. Harinath
PRESENTED BY:
ClariTrics Technologies
Agenda
· Introduction to Scala Play
· Key Features
· Anatomy of Scala Play Application
· Architecture of Scala play
· MVC Architecture in Scala play
· Developing Rest API in Play Framework
· Adding Dependency In Play Framework
· Request URL Mapping in play
· Reading Configuration File
· Concurrent Programming in Scala
· Packing for Production – Commonly used Commands
Introduction to Play Framework
· Is based on a lightweight, stateless, web-friendly, non blocking architecture.
· Built on Akka, provides predictable and minimal resources consumption (CPU, memory, threads)
for highly-scalable applications.
· Lots of built in features for fast development.
· Follows MVC architecture
Features of Play Framework
· Strong focus on productivity. Fast turnaround.
· Hot reloading: Fix the bug and hit reload!
· Type safe all the way, even templates and route files!
· Use Scala or Java: Your choice. You can even mix them!
· Predefined module for heavy lifting. Mail Service, Authentication
· Play Provides full stack
· Websocket support
· Template Engine for views
· Testing engine
Installation of Play Framework
· Dependencies
· Java 1.8
· Sbt 1.1.0
· Intellji or Eclipse
· Creating New Application
· Using Play Starter Projects
· Download Play Starter
· Create a new application using SBT
· Requires giter8
Steps to Initialize Play
Framework
· Unzip the package and place in the desired location
· Open the package in the IntelliJ editor File->Open
· Open the terminal inside the IntelliJ editor
· Run $sbt run - Process will take more time, please wait patiently
· Application will be opened at port 9000
Steps – Cont 1
· Download the File
· Unzip
Steps – Cont 2
· Open the Folder in Intellji
Steps – Cont 3
· Wait till it sync
· Open the terminal
Steps – Cont 4
· Type sbt run
· Application will be started at localhost:9000
Anatomy of Play Framework
MVC Architecture in Play
Playing Around Play Framework
· Accessing the End Point
· GET http://localhost:9000 - HTML View Page
· GET http://localhost:9000/count - Count gets incremented for each page refresh or request
· GET http://localhost:9000/message - Displays Hi! Message
· Important File to Remember in Play Framework
· build.sbt – Adding third party dependency from Maven
· Conf/applicaton.conf – Contains the Play framework settings
· Conf/routes – Contains the Url Mapping
· App folder holds the controllers, views, filters etc
Creating Rest API using Play!
Hello World using Play
· Go to conf/routes
· GET /greetings controllers.HelloWorldController.index
· HelloWorldController – name of the controller class file
· Index is the function name inside the controller class file
· Create a controller called HelloWorldController.scala in app/controller
package controllers
import javax.inject._
import play.api.mvc._
/**
* This controller creates an `Action` to handle HTTP requests to the
* application's home page.
*/
@Singleton
class HelloWorldController @Inject()(cc: ControllerComponents) extends AbstractController(cc) {
/**
Returns hello world
*/
def index = Action {
Ok("Hello World")
}
}
Output of Hello World
Adding Dependency in Play
· Using build.sbt
· // https://mvnrepository.com/artifact/org.apache.opennlp/opennlp-tools
libraryDependencies += "org.apache.opennlp" % "opennlp-tools" % "1.8.3"
· Using custom build jar
· Placing the custom build jar or jar which are not available in the Maven repository. We
should place those files inside lib in root location
Play Terminology
· Actions
· A Action is basically a function that handles a request and generates a result to be sent to
the client.
· Controllers
· A controller in Play is nothing more than an object that generates Action values. Controllers
are typically defined as classes to take advantage of Dependency Injection.
· Modules
· Play uses public modules to augment built-in functionality.
Returning Different Result Type
· val textResult = Ok("Hello World!")
· By default returns text/plain
· val xmlResult = Ok(<message>Hello World!</message>)
· Returns the result application/xml
· val htmlResult2 = Ok(<h1>Hello World!</h1>).as(HTML)
· Renders the HTML page
HTTP Routing
· Question ?
· Which file is responsible for URL mapping?
HTTP routing
· The built-in HTTP router
· The router is the component in charge of translating each incoming HTTP request to an
Action.
· An HTTP request is seen as an event by the MVC framework. This event contains two major
pieces of information:
· The request path (e.g. /clients/1542, /photos/list), including the query string
· The HTTP method (e.g. GET, POST)
· URI Pattern
· Static Path
· GET /clients/all controllers.Clients.list()
· Dynamic Parts
· GET /clients/:id controllers.Clients.show(id: Long)
· Router Feature
· What if I say you can do regex validation in route file itself !
Workflow of the Request from
Route file
Configuration File
· Play uses the Typesafe config library, but Play also provides a nice Scala wrapper called
Configuration with more advanced Scala features.
class MyController @Inject() (config: Configuration, c: ControllerComponents) extends
AbstractController(c) {
def getFoo = Action {
Ok(config.get[String]("name"))
}
}
Scala Concepts
· Writing Future Method
· A Future gives you a simple way to run an algorithm concurrently. A future starts running
concurrently when you create it and returns a result at some point, well, in the future.
val f = Future {
ComplexOperation // takes 100 sec approx
42
}
· Case class
· Case classes are like regular classes with a few key differences which we will go over. Case
classes are good for modeling immutable data
case class Book(isbn: String)
val frankenstein = Book("978-0486282114")
Creating Part of Speech Tagger
def convertPos(data:String) = Future {
var result:String = ""
if(data.isEmpty)
Future.successful(BadRequest("Data is empty"))
try {
// converting option[x] to x
// val sentence = data.get
// tokenize the sentence
val projectPath = Play.application().path();
var tokenModelIn = new FileInputStream(projectPath+"/conf/resource/en-token.bin")
val tokenModel = new TokenizerModel(tokenModelIn)
val tokenizer = new TokenizerME(tokenModel)
val tokens = tokenizer.tokenize(data)
// Parts-Of-Speech Tagging
// reading parts-of-speech model to a stream
var posModelIn = new FileInputStream(projectPath+ "/conf/resource/en-pos-maxent.bin")
// loading the parts-of-speech model from stream
val posModel = new POSModel(posModelIn)
// initializing the parts-of-speech tagger with model
val posTagger = new POSTaggerME(posModel)
// Tagger tagging the tokens
val tags = posTagger.tag(tokens)
// Getting the probabilities of the tags given to the tokens
val probs = posTagger.probs
// Iterates the token, tag and probability score
// Flattening to list makes into string
result++= (0 until tokens.length).map(i => tokens(i) + "t:t" + tags(i) + "t:t" + probs(i) + "n").flatten.toList
} catch {
case e: IOException =>
// Model loading failed, handle the error
e.printStackTrace()
}
result.toString
}
Commonly used Command
· Sbt run
· Sbt compile
· Sbt update
· Sbt dist
References
· Scala Programming Language (Wikipedia Article)
· Scala official site
· Typesafe
· Programming in Scala Book on Amazon
· Functional Programming Principles in Scala on Coursera
· Principles of Reactive Programming on Coursera
· Play Framework Official Website
· Play Framework (Wikipedia Article)
· Typesafe Activator
Questions?
harinath@claritrics.com
CONTACT:

More Related Content

What's hot

Geoscience satellite image processing
Geoscience satellite image processingGeoscience satellite image processing
Geoscience satellite image processing
gaurav jain
 
Parallel Database
Parallel DatabaseParallel Database
Parallel Database
VESIT/University of Mumbai
 
Caching
CachingCaching
Caching
Nascenia IT
 
Voice Assistant (1).pdf
Voice Assistant (1).pdfVoice Assistant (1).pdf
Voice Assistant (1).pdf
Thakurpushpendersing
 
Mini Project on Data Encryption & Decryption in JAVA
Mini Project on Data Encryption & Decryption in JAVAMini Project on Data Encryption & Decryption in JAVA
Mini Project on Data Encryption & Decryption in JAVA
chovatiyabhautik
 
Time Table Management System
Time Table Management SystemTime Table Management System
Time Table Management System
Muhammad Zeeshan
 
Graduation Project Documentation.PDF
Graduation Project Documentation.PDFGraduation Project Documentation.PDF
Graduation Project Documentation.PDF
Mostafa Elhoushi
 
Social Networking Project (website) full documentation
Social Networking Project (website) full documentation Social Networking Project (website) full documentation
Social Networking Project (website) full documentation
Tenzin Tendar
 
Weaviate and Pinecone Comparison.pdf
Weaviate and Pinecone Comparison.pdfWeaviate and Pinecone Comparison.pdf
Weaviate and Pinecone Comparison.pdf
Evgenios Skitsanos
 
Int306 02
Int306 02Int306 02
Int306 02
Sumit Mittu
 
Data Stream Management
Data Stream ManagementData Stream Management
Data Stream Management
k_tauhid
 
ACN Microproject .pdf
ACN Microproject .pdfACN Microproject .pdf
ACN Microproject .pdf
NayyarKhan8
 
Chapter 14
Chapter 14Chapter 14
Chapter 14
Ali Broumandnia
 
Kk8 melakukan instalasi software
Kk8 melakukan instalasi softwareKk8 melakukan instalasi software
Kk8 melakukan instalasi software
Wahyu S
 
InfoSphere BigInsights
InfoSphere BigInsightsInfoSphere BigInsights
InfoSphere BigInsights
Wilfried Hoge
 
Big data-analytics-cpe8035
Big data-analytics-cpe8035Big data-analytics-cpe8035
Big data-analytics-cpe8035
Neelam Rawat
 
A project report on chat application
A project report on chat applicationA project report on chat application
A project report on chat application
Kumar Gaurav
 
M.Sc. Research Proposal
M.Sc. Research ProposalM.Sc. Research Proposal
M.Sc. Research Proposal
Lighton Phiri
 
Security of the database
Security of the databaseSecurity of the database
Security of the database
Pratik Tamgadge
 
Web-RTC Based Conferencing Application
Web-RTC Based Conferencing Application Web-RTC Based Conferencing Application
Web-RTC Based Conferencing Application
Onkar Kadam
 

What's hot (20)

Geoscience satellite image processing
Geoscience satellite image processingGeoscience satellite image processing
Geoscience satellite image processing
 
Parallel Database
Parallel DatabaseParallel Database
Parallel Database
 
Caching
CachingCaching
Caching
 
Voice Assistant (1).pdf
Voice Assistant (1).pdfVoice Assistant (1).pdf
Voice Assistant (1).pdf
 
Mini Project on Data Encryption & Decryption in JAVA
Mini Project on Data Encryption & Decryption in JAVAMini Project on Data Encryption & Decryption in JAVA
Mini Project on Data Encryption & Decryption in JAVA
 
Time Table Management System
Time Table Management SystemTime Table Management System
Time Table Management System
 
Graduation Project Documentation.PDF
Graduation Project Documentation.PDFGraduation Project Documentation.PDF
Graduation Project Documentation.PDF
 
Social Networking Project (website) full documentation
Social Networking Project (website) full documentation Social Networking Project (website) full documentation
Social Networking Project (website) full documentation
 
Weaviate and Pinecone Comparison.pdf
Weaviate and Pinecone Comparison.pdfWeaviate and Pinecone Comparison.pdf
Weaviate and Pinecone Comparison.pdf
 
Int306 02
Int306 02Int306 02
Int306 02
 
Data Stream Management
Data Stream ManagementData Stream Management
Data Stream Management
 
ACN Microproject .pdf
ACN Microproject .pdfACN Microproject .pdf
ACN Microproject .pdf
 
Chapter 14
Chapter 14Chapter 14
Chapter 14
 
Kk8 melakukan instalasi software
Kk8 melakukan instalasi softwareKk8 melakukan instalasi software
Kk8 melakukan instalasi software
 
InfoSphere BigInsights
InfoSphere BigInsightsInfoSphere BigInsights
InfoSphere BigInsights
 
Big data-analytics-cpe8035
Big data-analytics-cpe8035Big data-analytics-cpe8035
Big data-analytics-cpe8035
 
A project report on chat application
A project report on chat applicationA project report on chat application
A project report on chat application
 
M.Sc. Research Proposal
M.Sc. Research ProposalM.Sc. Research Proposal
M.Sc. Research Proposal
 
Security of the database
Security of the databaseSecurity of the database
Security of the database
 
Web-RTC Based Conferencing Application
Web-RTC Based Conferencing Application Web-RTC Based Conferencing Application
Web-RTC Based Conferencing Application
 

Similar to Play Framework

Play framework productivity formula
Play framework   productivity formula Play framework   productivity formula
Play framework productivity formula
Sorin Chiprian
 
Symfony HTTP Kernel for refactoring legacy apps: the eZ Publish case study - ...
Symfony HTTP Kernel for refactoring legacy apps: the eZ Publish case study - ...Symfony HTTP Kernel for refactoring legacy apps: the eZ Publish case study - ...
Symfony HTTP Kernel for refactoring legacy apps: the eZ Publish case study - ...
Gaetano Giunta
 
introduction to node.js
introduction to node.jsintroduction to node.js
introduction to node.js
orkaplan
 
Play Framework: async I/O with Java and Scala
Play Framework: async I/O with Java and ScalaPlay Framework: async I/O with Java and Scala
Play Framework: async I/O with Java and Scala
Yevgeniy Brikman
 
Binary Studio Academy: Concurrency in C# 5.0
Binary Studio Academy: Concurrency in C# 5.0Binary Studio Academy: Concurrency in C# 5.0
Binary Studio Academy: Concurrency in C# 5.0
Binary Studio
 
Introduction tomcat7 servlet3
Introduction tomcat7 servlet3Introduction tomcat7 servlet3
Introduction tomcat7 servlet3
JavaEE Trainers
 
Basic Understanding and Implement of Node.js
Basic Understanding and Implement of Node.jsBasic Understanding and Implement of Node.js
Basic Understanding and Implement of Node.js
Gary Yeh
 
Solving anything in VCL
Solving anything in VCLSolving anything in VCL
Solving anything in VCL
Fastly
 
nodejs_at_a_glance.ppt
nodejs_at_a_glance.pptnodejs_at_a_glance.ppt
nodejs_at_a_glance.ppt
WalaSidhom1
 
Node.js Workshop - Sela SDP 2015
Node.js Workshop  - Sela SDP 2015Node.js Workshop  - Sela SDP 2015
Node.js Workshop - Sela SDP 2015
Nir Noy
 
Copper: A high performance workflow engine
Copper: A high performance workflow engineCopper: A high performance workflow engine
Copper: A high performance workflow engine
dmoebius
 
Build powerfull and smart web applications with Symfony2
Build powerfull and smart web applications with Symfony2Build powerfull and smart web applications with Symfony2
Build powerfull and smart web applications with Symfony2
Hugo Hamon
 
Distributed & Highly Available server applications in Java and Scala
Distributed & Highly Available server applications in Java and ScalaDistributed & Highly Available server applications in Java and Scala
Distributed & Highly Available server applications in Java and Scala
Max Alexejev
 
Web Server and how we can design app in C#
Web Server and how we can design app  in C#Web Server and how we can design app  in C#
Web Server and how we can design app in C#
caohansnnuedu
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
Richard Lee
 
Module design pattern i.e. express js
Module design pattern i.e. express jsModule design pattern i.e. express js
Module design pattern i.e. express js
Ahmed Assaf
 
WebTalk - Implementing Web Services with a dedicated Java daemon
WebTalk - Implementing Web Services with a dedicated Java daemonWebTalk - Implementing Web Services with a dedicated Java daemon
WebTalk - Implementing Web Services with a dedicated Java daemon
Geert Van Pamel
 
Everything you wanted to know about writing async, concurrent http apps in java
Everything you wanted to know about writing async, concurrent http apps in java Everything you wanted to know about writing async, concurrent http apps in java
Everything you wanted to know about writing async, concurrent http apps in java
Baruch Sadogursky
 
What's New in .Net 4.5
What's New in .Net 4.5What's New in .Net 4.5
What's New in .Net 4.5
Malam Team
 
Apache Samza 1.0 - What's New, What's Next
Apache Samza 1.0 - What's New, What's NextApache Samza 1.0 - What's New, What's Next
Apache Samza 1.0 - What's New, What's Next
Prateek Maheshwari
 

Similar to Play Framework (20)

Play framework productivity formula
Play framework   productivity formula Play framework   productivity formula
Play framework productivity formula
 
Symfony HTTP Kernel for refactoring legacy apps: the eZ Publish case study - ...
Symfony HTTP Kernel for refactoring legacy apps: the eZ Publish case study - ...Symfony HTTP Kernel for refactoring legacy apps: the eZ Publish case study - ...
Symfony HTTP Kernel for refactoring legacy apps: the eZ Publish case study - ...
 
introduction to node.js
introduction to node.jsintroduction to node.js
introduction to node.js
 
Play Framework: async I/O with Java and Scala
Play Framework: async I/O with Java and ScalaPlay Framework: async I/O with Java and Scala
Play Framework: async I/O with Java and Scala
 
Binary Studio Academy: Concurrency in C# 5.0
Binary Studio Academy: Concurrency in C# 5.0Binary Studio Academy: Concurrency in C# 5.0
Binary Studio Academy: Concurrency in C# 5.0
 
Introduction tomcat7 servlet3
Introduction tomcat7 servlet3Introduction tomcat7 servlet3
Introduction tomcat7 servlet3
 
Basic Understanding and Implement of Node.js
Basic Understanding and Implement of Node.jsBasic Understanding and Implement of Node.js
Basic Understanding and Implement of Node.js
 
Solving anything in VCL
Solving anything in VCLSolving anything in VCL
Solving anything in VCL
 
nodejs_at_a_glance.ppt
nodejs_at_a_glance.pptnodejs_at_a_glance.ppt
nodejs_at_a_glance.ppt
 
Node.js Workshop - Sela SDP 2015
Node.js Workshop  - Sela SDP 2015Node.js Workshop  - Sela SDP 2015
Node.js Workshop - Sela SDP 2015
 
Copper: A high performance workflow engine
Copper: A high performance workflow engineCopper: A high performance workflow engine
Copper: A high performance workflow engine
 
Build powerfull and smart web applications with Symfony2
Build powerfull and smart web applications with Symfony2Build powerfull and smart web applications with Symfony2
Build powerfull and smart web applications with Symfony2
 
Distributed & Highly Available server applications in Java and Scala
Distributed & Highly Available server applications in Java and ScalaDistributed & Highly Available server applications in Java and Scala
Distributed & Highly Available server applications in Java and Scala
 
Web Server and how we can design app in C#
Web Server and how we can design app  in C#Web Server and how we can design app  in C#
Web Server and how we can design app in C#
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
 
Module design pattern i.e. express js
Module design pattern i.e. express jsModule design pattern i.e. express js
Module design pattern i.e. express js
 
WebTalk - Implementing Web Services with a dedicated Java daemon
WebTalk - Implementing Web Services with a dedicated Java daemonWebTalk - Implementing Web Services with a dedicated Java daemon
WebTalk - Implementing Web Services with a dedicated Java daemon
 
Everything you wanted to know about writing async, concurrent http apps in java
Everything you wanted to know about writing async, concurrent http apps in java Everything you wanted to know about writing async, concurrent http apps in java
Everything you wanted to know about writing async, concurrent http apps in java
 
What's New in .Net 4.5
What's New in .Net 4.5What's New in .Net 4.5
What's New in .Net 4.5
 
Apache Samza 1.0 - What's New, What's Next
Apache Samza 1.0 - What's New, What's NextApache Samza 1.0 - What's New, What's Next
Apache Samza 1.0 - What's New, What's Next
 

Recently uploaded

Secure-by-Design Using Hardware and Software Protection for FDA Compliance
Secure-by-Design Using Hardware and Software Protection for FDA ComplianceSecure-by-Design Using Hardware and Software Protection for FDA Compliance
Secure-by-Design Using Hardware and Software Protection for FDA Compliance
ICS
 
Operational ease MuleSoft and Salesforce Service Cloud Solution v1.0.pptx
Operational ease MuleSoft and Salesforce Service Cloud Solution v1.0.pptxOperational ease MuleSoft and Salesforce Service Cloud Solution v1.0.pptx
Operational ease MuleSoft and Salesforce Service Cloud Solution v1.0.pptx
sandeepmenon62
 
美洲杯赔率投注网【​网址​🎉3977·EE​🎉】
美洲杯赔率投注网【​网址​🎉3977·EE​🎉】美洲杯赔率投注网【​网址​🎉3977·EE​🎉】
美洲杯赔率投注网【​网址​🎉3977·EE​🎉】
widenerjobeyrl638
 
Microsoft-Power-Platform-Adoption-Planning.pptx
Microsoft-Power-Platform-Adoption-Planning.pptxMicrosoft-Power-Platform-Adoption-Planning.pptx
Microsoft-Power-Platform-Adoption-Planning.pptx
jrodriguezq3110
 
Call Girls Bangalore🔥7023059433🔥Best Profile Escorts in Bangalore Available 24/7
Call Girls Bangalore🔥7023059433🔥Best Profile Escorts in Bangalore Available 24/7Call Girls Bangalore🔥7023059433🔥Best Profile Escorts in Bangalore Available 24/7
Call Girls Bangalore🔥7023059433🔥Best Profile Escorts in Bangalore Available 24/7
manji sharman06
 
Alluxio Webinar | 10x Faster Trino Queries on Your Data Platform
Alluxio Webinar | 10x Faster Trino Queries on Your Data PlatformAlluxio Webinar | 10x Faster Trino Queries on Your Data Platform
Alluxio Webinar | 10x Faster Trino Queries on Your Data Platform
Alluxio, Inc.
 
Flutter vs. React Native: A Detailed Comparison for App Development in 2024
Flutter vs. React Native: A Detailed Comparison for App Development in 2024Flutter vs. React Native: A Detailed Comparison for App Development in 2024
Flutter vs. React Native: A Detailed Comparison for App Development in 2024
dhavalvaghelanectarb
 
Hands-on with Apache Druid: Installation & Data Ingestion Steps
Hands-on with Apache Druid: Installation & Data Ingestion StepsHands-on with Apache Druid: Installation & Data Ingestion Steps
Hands-on with Apache Druid: Installation & Data Ingestion Steps
servicesNitor
 
Computer Science & Engineering VI Sem- New Syllabus.pdf
Computer Science & Engineering VI Sem- New Syllabus.pdfComputer Science & Engineering VI Sem- New Syllabus.pdf
Computer Science & Engineering VI Sem- New Syllabus.pdf
chandangoswami40933
 
Upturn India Technologies - Web development company in Nashik
Upturn India Technologies - Web development company in NashikUpturn India Technologies - Web development company in Nashik
Upturn India Technologies - Web development company in Nashik
Upturn India Technologies
 
Why Apache Kafka Clusters Are Like Galaxies (And Other Cosmic Kafka Quandarie...
Why Apache Kafka Clusters Are Like Galaxies (And Other Cosmic Kafka Quandarie...Why Apache Kafka Clusters Are Like Galaxies (And Other Cosmic Kafka Quandarie...
Why Apache Kafka Clusters Are Like Galaxies (And Other Cosmic Kafka Quandarie...
Paul Brebner
 
ppt on the brain chip neuralink.pptx
ppt  on   the brain  chip neuralink.pptxppt  on   the brain  chip neuralink.pptx
ppt on the brain chip neuralink.pptx
Reetu63
 
What’s New in VictoriaLogs - Q2 2024 Update
What’s New in VictoriaLogs - Q2 2024 UpdateWhat’s New in VictoriaLogs - Q2 2024 Update
What’s New in VictoriaLogs - Q2 2024 Update
VictoriaMetrics
 
Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)
Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)
Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)
safelyiotech
 
What is Continuous Testing in DevOps - A Definitive Guide.pdf
What is Continuous Testing in DevOps - A Definitive Guide.pdfWhat is Continuous Testing in DevOps - A Definitive Guide.pdf
What is Continuous Testing in DevOps - A Definitive Guide.pdf
kalichargn70th171
 
Baha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdf
Baha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdfBaha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdf
Baha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdf
Baha Majid
 
Stork Product Overview: An AI-Powered Autonomous Delivery Fleet
Stork Product Overview: An AI-Powered Autonomous Delivery FleetStork Product Overview: An AI-Powered Autonomous Delivery Fleet
Stork Product Overview: An AI-Powered Autonomous Delivery Fleet
Vince Scalabrino
 
Going AOT: Everything you need to know about GraalVM for Java applications
Going AOT: Everything you need to know about GraalVM for Java applicationsGoing AOT: Everything you need to know about GraalVM for Java applications
Going AOT: Everything you need to know about GraalVM for Java applications
Alina Yurenko
 
The Power of Visual Regression Testing_ Why It Is Critical for Enterprise App...
The Power of Visual Regression Testing_ Why It Is Critical for Enterprise App...The Power of Visual Regression Testing_ Why It Is Critical for Enterprise App...
The Power of Visual Regression Testing_ Why It Is Critical for Enterprise App...
kalichargn70th171
 
Streamlining End-to-End Testing Automation
Streamlining End-to-End Testing AutomationStreamlining End-to-End Testing Automation
Streamlining End-to-End Testing Automation
Anand Bagmar
 

Recently uploaded (20)

Secure-by-Design Using Hardware and Software Protection for FDA Compliance
Secure-by-Design Using Hardware and Software Protection for FDA ComplianceSecure-by-Design Using Hardware and Software Protection for FDA Compliance
Secure-by-Design Using Hardware and Software Protection for FDA Compliance
 
Operational ease MuleSoft and Salesforce Service Cloud Solution v1.0.pptx
Operational ease MuleSoft and Salesforce Service Cloud Solution v1.0.pptxOperational ease MuleSoft and Salesforce Service Cloud Solution v1.0.pptx
Operational ease MuleSoft and Salesforce Service Cloud Solution v1.0.pptx
 
美洲杯赔率投注网【​网址​🎉3977·EE​🎉】
美洲杯赔率投注网【​网址​🎉3977·EE​🎉】美洲杯赔率投注网【​网址​🎉3977·EE​🎉】
美洲杯赔率投注网【​网址​🎉3977·EE​🎉】
 
Microsoft-Power-Platform-Adoption-Planning.pptx
Microsoft-Power-Platform-Adoption-Planning.pptxMicrosoft-Power-Platform-Adoption-Planning.pptx
Microsoft-Power-Platform-Adoption-Planning.pptx
 
Call Girls Bangalore🔥7023059433🔥Best Profile Escorts in Bangalore Available 24/7
Call Girls Bangalore🔥7023059433🔥Best Profile Escorts in Bangalore Available 24/7Call Girls Bangalore🔥7023059433🔥Best Profile Escorts in Bangalore Available 24/7
Call Girls Bangalore🔥7023059433🔥Best Profile Escorts in Bangalore Available 24/7
 
Alluxio Webinar | 10x Faster Trino Queries on Your Data Platform
Alluxio Webinar | 10x Faster Trino Queries on Your Data PlatformAlluxio Webinar | 10x Faster Trino Queries on Your Data Platform
Alluxio Webinar | 10x Faster Trino Queries on Your Data Platform
 
Flutter vs. React Native: A Detailed Comparison for App Development in 2024
Flutter vs. React Native: A Detailed Comparison for App Development in 2024Flutter vs. React Native: A Detailed Comparison for App Development in 2024
Flutter vs. React Native: A Detailed Comparison for App Development in 2024
 
Hands-on with Apache Druid: Installation & Data Ingestion Steps
Hands-on with Apache Druid: Installation & Data Ingestion StepsHands-on with Apache Druid: Installation & Data Ingestion Steps
Hands-on with Apache Druid: Installation & Data Ingestion Steps
 
Computer Science & Engineering VI Sem- New Syllabus.pdf
Computer Science & Engineering VI Sem- New Syllabus.pdfComputer Science & Engineering VI Sem- New Syllabus.pdf
Computer Science & Engineering VI Sem- New Syllabus.pdf
 
Upturn India Technologies - Web development company in Nashik
Upturn India Technologies - Web development company in NashikUpturn India Technologies - Web development company in Nashik
Upturn India Technologies - Web development company in Nashik
 
Why Apache Kafka Clusters Are Like Galaxies (And Other Cosmic Kafka Quandarie...
Why Apache Kafka Clusters Are Like Galaxies (And Other Cosmic Kafka Quandarie...Why Apache Kafka Clusters Are Like Galaxies (And Other Cosmic Kafka Quandarie...
Why Apache Kafka Clusters Are Like Galaxies (And Other Cosmic Kafka Quandarie...
 
ppt on the brain chip neuralink.pptx
ppt  on   the brain  chip neuralink.pptxppt  on   the brain  chip neuralink.pptx
ppt on the brain chip neuralink.pptx
 
What’s New in VictoriaLogs - Q2 2024 Update
What’s New in VictoriaLogs - Q2 2024 UpdateWhat’s New in VictoriaLogs - Q2 2024 Update
What’s New in VictoriaLogs - Q2 2024 Update
 
Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)
Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)
Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)
 
What is Continuous Testing in DevOps - A Definitive Guide.pdf
What is Continuous Testing in DevOps - A Definitive Guide.pdfWhat is Continuous Testing in DevOps - A Definitive Guide.pdf
What is Continuous Testing in DevOps - A Definitive Guide.pdf
 
Baha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdf
Baha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdfBaha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdf
Baha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdf
 
Stork Product Overview: An AI-Powered Autonomous Delivery Fleet
Stork Product Overview: An AI-Powered Autonomous Delivery FleetStork Product Overview: An AI-Powered Autonomous Delivery Fleet
Stork Product Overview: An AI-Powered Autonomous Delivery Fleet
 
Going AOT: Everything you need to know about GraalVM for Java applications
Going AOT: Everything you need to know about GraalVM for Java applicationsGoing AOT: Everything you need to know about GraalVM for Java applications
Going AOT: Everything you need to know about GraalVM for Java applications
 
The Power of Visual Regression Testing_ Why It Is Critical for Enterprise App...
The Power of Visual Regression Testing_ Why It Is Critical for Enterprise App...The Power of Visual Regression Testing_ Why It Is Critical for Enterprise App...
The Power of Visual Regression Testing_ Why It Is Critical for Enterprise App...
 
Streamlining End-to-End Testing Automation
Streamlining End-to-End Testing AutomationStreamlining End-to-End Testing Automation
Streamlining End-to-End Testing Automation
 

Play Framework

  • 1. Play Framework Understanding using Scala K. Harinath PRESENTED BY: ClariTrics Technologies
  • 2. Agenda · Introduction to Scala Play · Key Features · Anatomy of Scala Play Application · Architecture of Scala play · MVC Architecture in Scala play · Developing Rest API in Play Framework · Adding Dependency In Play Framework · Request URL Mapping in play · Reading Configuration File · Concurrent Programming in Scala · Packing for Production – Commonly used Commands
  • 3. Introduction to Play Framework · Is based on a lightweight, stateless, web-friendly, non blocking architecture. · Built on Akka, provides predictable and minimal resources consumption (CPU, memory, threads) for highly-scalable applications. · Lots of built in features for fast development. · Follows MVC architecture
  • 4. Features of Play Framework · Strong focus on productivity. Fast turnaround. · Hot reloading: Fix the bug and hit reload! · Type safe all the way, even templates and route files! · Use Scala or Java: Your choice. You can even mix them! · Predefined module for heavy lifting. Mail Service, Authentication · Play Provides full stack · Websocket support · Template Engine for views · Testing engine
  • 5. Installation of Play Framework · Dependencies · Java 1.8 · Sbt 1.1.0 · Intellji or Eclipse · Creating New Application · Using Play Starter Projects · Download Play Starter · Create a new application using SBT · Requires giter8
  • 6. Steps to Initialize Play Framework · Unzip the package and place in the desired location · Open the package in the IntelliJ editor File->Open · Open the terminal inside the IntelliJ editor · Run $sbt run - Process will take more time, please wait patiently · Application will be opened at port 9000
  • 7. Steps – Cont 1 · Download the File · Unzip
  • 8. Steps – Cont 2 · Open the Folder in Intellji
  • 9. Steps – Cont 3 · Wait till it sync · Open the terminal
  • 10. Steps – Cont 4 · Type sbt run · Application will be started at localhost:9000
  • 11. Anatomy of Play Framework
  • 13. Playing Around Play Framework · Accessing the End Point · GET http://localhost:9000 - HTML View Page · GET http://localhost:9000/count - Count gets incremented for each page refresh or request · GET http://localhost:9000/message - Displays Hi! Message · Important File to Remember in Play Framework · build.sbt – Adding third party dependency from Maven · Conf/applicaton.conf – Contains the Play framework settings · Conf/routes – Contains the Url Mapping · App folder holds the controllers, views, filters etc
  • 14. Creating Rest API using Play!
  • 15. Hello World using Play · Go to conf/routes · GET /greetings controllers.HelloWorldController.index · HelloWorldController – name of the controller class file · Index is the function name inside the controller class file · Create a controller called HelloWorldController.scala in app/controller package controllers import javax.inject._ import play.api.mvc._ /** * This controller creates an `Action` to handle HTTP requests to the * application's home page. */ @Singleton class HelloWorldController @Inject()(cc: ControllerComponents) extends AbstractController(cc) { /** Returns hello world */ def index = Action { Ok("Hello World") } }
  • 17. Adding Dependency in Play · Using build.sbt · // https://mvnrepository.com/artifact/org.apache.opennlp/opennlp-tools libraryDependencies += "org.apache.opennlp" % "opennlp-tools" % "1.8.3" · Using custom build jar · Placing the custom build jar or jar which are not available in the Maven repository. We should place those files inside lib in root location
  • 18. Play Terminology · Actions · A Action is basically a function that handles a request and generates a result to be sent to the client. · Controllers · A controller in Play is nothing more than an object that generates Action values. Controllers are typically defined as classes to take advantage of Dependency Injection. · Modules · Play uses public modules to augment built-in functionality.
  • 19. Returning Different Result Type · val textResult = Ok("Hello World!") · By default returns text/plain · val xmlResult = Ok(<message>Hello World!</message>) · Returns the result application/xml · val htmlResult2 = Ok(<h1>Hello World!</h1>).as(HTML) · Renders the HTML page
  • 20. HTTP Routing · Question ? · Which file is responsible for URL mapping?
  • 21. HTTP routing · The built-in HTTP router · The router is the component in charge of translating each incoming HTTP request to an Action. · An HTTP request is seen as an event by the MVC framework. This event contains two major pieces of information: · The request path (e.g. /clients/1542, /photos/list), including the query string · The HTTP method (e.g. GET, POST) · URI Pattern · Static Path · GET /clients/all controllers.Clients.list() · Dynamic Parts · GET /clients/:id controllers.Clients.show(id: Long) · Router Feature · What if I say you can do regex validation in route file itself !
  • 22. Workflow of the Request from Route file
  • 23. Configuration File · Play uses the Typesafe config library, but Play also provides a nice Scala wrapper called Configuration with more advanced Scala features. class MyController @Inject() (config: Configuration, c: ControllerComponents) extends AbstractController(c) { def getFoo = Action { Ok(config.get[String]("name")) } }
  • 24. Scala Concepts · Writing Future Method · A Future gives you a simple way to run an algorithm concurrently. A future starts running concurrently when you create it and returns a result at some point, well, in the future. val f = Future { ComplexOperation // takes 100 sec approx 42 } · Case class · Case classes are like regular classes with a few key differences which we will go over. Case classes are good for modeling immutable data case class Book(isbn: String) val frankenstein = Book("978-0486282114")
  • 25. Creating Part of Speech Tagger def convertPos(data:String) = Future { var result:String = "" if(data.isEmpty) Future.successful(BadRequest("Data is empty")) try { // converting option[x] to x // val sentence = data.get // tokenize the sentence val projectPath = Play.application().path(); var tokenModelIn = new FileInputStream(projectPath+"/conf/resource/en-token.bin") val tokenModel = new TokenizerModel(tokenModelIn) val tokenizer = new TokenizerME(tokenModel) val tokens = tokenizer.tokenize(data) // Parts-Of-Speech Tagging // reading parts-of-speech model to a stream var posModelIn = new FileInputStream(projectPath+ "/conf/resource/en-pos-maxent.bin") // loading the parts-of-speech model from stream val posModel = new POSModel(posModelIn) // initializing the parts-of-speech tagger with model val posTagger = new POSTaggerME(posModel) // Tagger tagging the tokens val tags = posTagger.tag(tokens) // Getting the probabilities of the tags given to the tokens val probs = posTagger.probs // Iterates the token, tag and probability score // Flattening to list makes into string result++= (0 until tokens.length).map(i => tokens(i) + "t:t" + tags(i) + "t:t" + probs(i) + "n").flatten.toList } catch { case e: IOException => // Model loading failed, handle the error e.printStackTrace() } result.toString }
  • 26. Commonly used Command · Sbt run · Sbt compile · Sbt update · Sbt dist
  • 27. References · Scala Programming Language (Wikipedia Article) · Scala official site · Typesafe · Programming in Scala Book on Amazon · Functional Programming Principles in Scala on Coursera · Principles of Reactive Programming on Coursera · Play Framework Official Website · Play Framework (Wikipedia Article) · Typesafe Activator