Rest Services with Play Framework, MySQL, Adding Security with JWT México
Independent Consultor #geek #traveler #speaker Community Leader JDuchess Chapter Guatemala, Devs+502 Ex-JUG Member Guatemala Java Users Group (GuateJUG) Independent Consultor Full Stack Developer, Front-end y Back-end with Java, Mobile Development Android and iOS CTO at Produactivity #geek #traveler #speaker Mercedes Wyss @itrjwyss
Agenda Play Framework Web Services Restful JSONs Database Connection (JPA, JDBC) JWT (Json Web Tokens)
Agenda Play Framework Web Services Restful JSONs Database Connection (JPA, JDBC) JWT (Json Web Tokens)
Play Framework Makes it easy to build web applications with Java and Scala. Is based on a lightweight, stateless, web-friendly architecture. Built on Akka, provides predictable and minimal resources consumption (CPU, memory, threads) for highly-scalable applications.
Servidor: 1 CPU 2 GB Ram
Play Framework Develop using Java or Scala Is reactive Use the architecture MVC Uses Netty as App Server, AKKA Http since 2.6.x (Fewer configurations) Simulates the behavior of JRebel (more code, less deploys)
JVM
Reactive
MVC
How start a Play project? We need to use SBT Create sbt new playframework/play-scala-seed.g8 sbt new playframework/play-java-seed.g8 Deploy sbt run
Full Project Structure
Simple Project Structure
Agenda Play Framework Web Services Restful JSONs Database connection (JPA, JDBC) JWT (Json Web Tokens)
Web Services HyperText Transfer Protocol (HTTP) Allows communication between a client and a server Provide a standard means of interoperating between different software apps Characterized for interoperability and extensibility Based on XML
Linda. com (June 2017) https://www. lynda
SOAP Simple Object Access Protocol XML-based Use WSDL as specification description (Web Services Description Language) Need to follow a communication protocol
Restful Software Architecture based on HTTP method (Get, Post, Put, Delete, etc) Typically use JSON, but can use XML, Text
Madhaiyan Muthu (June 2017) https://www. slideshare
Agenda Play Framework Web Services Restful JSONs Database connection (JPA, JDBC) JWT (Json Web Tokens)
JSON JavaScript Object Notation Is a lightweight data-interchange format Self-describing Human-reading Is a Protocol
JSON Example
JSON Scheme
Package controllers; import play.libs.Json; import play.mvc.Controller; import play.mvc.Result; public class HomeController extends Controller { public Result index(){ JsonNode json = request().body().asJson(); PostRequest request = Json.fromJson(json, PostRequest.class); return ok(Json.toJson(request)); }
Agenda Play Framework Web Services Restful JSONs JWT (Json Web Tokens) Database connection (JPA, JDBC)
JWT Is an open standard (RFC 7519) that defines a compact and self-contained way for securely transmitting information between parties as a JSON object.
Auth0 (June 2017) https://cdn.auth0.com/content/jwt/jwt-diagram.png
JWT Structure
JWT Structure
JWT Structure
Agenda Play Framework Web Services Restful JSONs JWT (Json Web Tokens) Database connection (JPA, JDBC)
To End Let’s Finish our Exercise México