Slide 1

Slide 1 text

Matt Raible | @mraible October 8, 2021 Java REST API Comparison Micronaut, Quarkus, and Spring Boot

Slide 2

Slide 2 text

@mraible Who is Matt Raible? Father, Husband, Skier, Mountain Biker, Whitewater Rafter Bus Lover Web Developer and Java Champion Okta Developer Advocate Blogger on raibledesigns.com and developer.okta.com/blog @mraible

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

@mraible Today’s Agenda Why Java? Build { REST, GraphQL } APIs with Java Secure your APIs with OAuth 2.1 Build with Docker Go Native with GraalVM https://unsplash.com/photos/JsTmUnHdVYQ

Slide 7

Slide 7 text

@mraible Why Java? 25+ Years of use, abuse, and improvements Open Source code is available; many popular open source frameworks and tools Hugely Popular and widely used by many enterprises and web-scale companies

Slide 8

Slide 8 text

@mraible Download the JDK from OpenJDK https://jdk.java.net/17 Or from Adoptium https://adoptium.net Get Started with Java 17

Slide 9

Slide 9 text

@mraible Get Started with Java 17 Better yet, use SDKMAN! curl -s https://get.sdkman.io | bash 
 sdk install java 17-open

Slide 10

Slide 10 text

Java Releases and Features

Slide 11

Slide 11 text

https://developer.okta.com/blog/2020/01/09/java-rest-api-showdown Build REST APIs with Java

Slide 12

Slide 12 text

Serverless 💵 💸 https://unsplash.com/photos/glRqyWJgUeY

Slide 13

Slide 13 text

@mraible sdk install micronaut mn create-app com.okta.rest.app \ -b maven -f security-jwt Get Started with Micronaut

Slide 14

Slide 14 text

https://micronaut.io/launch

Slide 15

Slide 15 text

package com.okta.rest.controller; import io.micronaut.http.MediaType; import io.micronaut.http.annotation.Controller; import io.micronaut.http.annotation.Get; import io.micronaut.http.annotation.Produces; import io.micronaut.security.annotation.Secured; import io.micronaut.security.rules.SecurityRule; import java.security.Principal; @Controller("/hello") public class HelloController { @Get @Secured(SecurityRule.IS_AUTHENTICATED) @Produces(MediaType.TEXT_PLAIN) public String hello(Principal principal) { return "Hello, " + principal.getName() + "!"; } }

Slide 16

Slide 16 text

micronaut.security.enabled=true micronaut.security.token.jwt.enabled=true micronaut.security.token.jwt.signatures.jwks.okta.url= https://dev-133337.okta.com/oauth2/default/v1/keys Micronaut JWT Security

Slide 17

Slide 17 text

micronaut.security.enabled=true micronaut.security.token.jwt.enabled=true micronaut.security.token.jwt.signatures.jwks.okta.url= https://dev-133337.okta.com/oauth2/default/v1/keys Micronaut JWT Security https://micronaut-projects.github.io/micronaut-security/latest/guide/#jwt

Slide 18

Slide 18 text

Install HTTPie (a better cURL) $ install httpie https://httpie.org

Slide 19

Slide 19 text

Test Micronaut with HTTPie https://httpie.org mvn mn:run http :8080/hello TOKEN=eyJraWQiOiJxOE1QMjFNNHZCVmxOSkxGbFFWNlN... http :8080/hello Authorization:"Bearer $TOKEN"

Slide 20

Slide 20 text

Verify Micronaut API with HTTPie

Slide 21

Slide 21 text

@mraible Get Started with Quarkus mvn io.quarkus:quarkus-maven-plugin:2.3.0.Final:create \ -DprojectGroupId=com.okta.rest \ -DprojectArtifactId=quarkus \ -DclassName="com.okta.rest.quarkus.HelloResource" \ -Dpath="/hello" \ -Dextensions="smallrye-jwt,resteasy-reactive"

Slide 22

Slide 22 text

https://code.quarkus.io

Slide 23

Slide 23 text

package com.okta.rest.quarkus; import io.quarkus.security.Authenticated; import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.SecurityContext; import java.security.Principal; @Path("/hello") public class HelloResource { @GET @Path("/") @Authenticated @Produces(MediaType.TEXT_PLAIN) public String hello(@Context SecurityContext context) { Principal userPrincipal = context.getUserPrincipal(); return "Hello, " + userPrincipal.getName() + "!"; } }

Slide 24

Slide 24 text

mp.jwt.verify.publickey.location= https://dev-133337.okta.com/ oauth2/default/v1/keys mp.jwt.verify.issuer=https:// dev-133337.okta.com/oauth2/ default MicroProfile JWT Security https://www.eclipse.org/community/eclipse_newsletter/2017/september/article2.php

Slide 25

Slide 25 text

mp.jwt.verify.publickey.location= https://dev-133337.okta.com/ oauth2/default/v1/keys mp.jwt.verify.issuer=https:// dev-133337.okta.com/oauth2/ default MicroProfile JWT Security https://www.eclipse.org/community/eclipse_newsletter/2017/september/article2.php

Slide 26

Slide 26 text

No content

Slide 27

Slide 27 text

Test Quarkus with HTTPie https://httpie.org mvn quarkus:dev http :8080/hello TOKEN=eyJraWQiOiJxOE1QMjFNNHZCVmxOSkxGbFFWNlN... http :8080/hello Authorization:"Bearer $TOKEN"

Slide 28

Slide 28 text

Verify Quarkus API with HTTPie

Slide 29

Slide 29 text

@mraible Get Started with Spring Boot http https://start.spring.io/starter.zip \ dependencies==web,oauth2-resource-server,native \ packageName==com.okta.rest \ name==spring-boot \ type==maven-project \ baseDir==spring-boot | tar -xzvf -

Slide 30

Slide 30 text

https://start.spring.io

Slide 31

Slide 31 text

package com.okta.rest.controller; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; import java.security.Principal; @RestController public class HelloController { @GetMapping("/hello") public String hello(Principal principal) { return "Hello, " + principal.getName() + "!"; } }

Slide 32

Slide 32 text

Spring Security OAuth 2.0 Resource Server https://docs.spring.io/spring-security/site/docs/current/reference/html5/#oauth2resourceserver okta.oauth2.issuer=https://dev-133337.okta.com/ oauth2/default

Slide 33

Slide 33 text

Test Spring Boot with HTTPie https://httpie.org mvn spring-boot:run http :8080/hello TOKEN=eyJraWQiOiJxOE1QMjFNNHZCVmxOSkxGbFFWNlN... http :8080/hello Authorization:"Bearer $TOKEN"

Slide 34

Slide 34 text

Verify Spring Boot API with HTTPie

Slide 35

Slide 35 text

@mraible Startup Performance Milliseconds 0 750 1500 2250 3000 Micronaut Quarkus Spring Boot 2,262 632 599 1,297 1,582 479 Dev Startup (mvn) Packaged Startup (java -jar) https://developer.okta.com/blog/2020/01/09/java-rest-api-showdown

Slide 36

Slide 36 text

@mraible Build GraphQL APIs with Java Why GraphQL? Does your favorite framework support GraphQL? Micronaut https://micronaut-projects.github.io/micronaut-graphql/latest/guide Quarkus https://quarkus.io/guides/smallrye-graphql Spring Boot https://spring.io/projects/spring-graphql

Slide 37

Slide 37 text

@mraible Secure your API with OAuth 2.0 https://aaronparecki.com/2019/12/12/21/its-time-for-oauth-2-dot-1

Slide 38

Slide 38 text

@mraible Secure your API with OAuth 2.1 https://oauth.net/2.1 PKCE is required for all clients using the authorization code flow Redirect URIs must be compared using exact string matching The Implicit grant is omitted from this specification The Resource Owner Password Credentials grant is omitted from this specification Bearer token usage omits the use of bearer tokens in the query string of URIs Refresh tokens for public clients must either be sender-constrained or one-time use

Slide 39

Slide 39 text

@mraible Authenticate with OpenID Connect (OIDC) What is OpenID Connect? Does your favorite framework support OIDC authentication? Micronaut https://guides.micronaut.io/latest/micronaut-oauth2-okta.html Quarkus https://quarkus.io/guides/security-openid-connect-web-authentication Spring Boot https://docs.spring.io/spring-security/site/docs/current/reference/html5/#oauth2login

Slide 40

Slide 40 text

What about testing?

Slide 41

Slide 41 text

@mraible Build with Docker Create a Dockerfile 
 FROM openjdk:17-alpine ARG JAR_FILE=target/*.jar COPY ${JAR_FILE} app.jar EXPOSE 8080 ENTRYPOINT ["java","-jar","/app.jar"]

Slide 42

Slide 42 text

@mraible Build with Docker Build your image docker build -t . Run your image docker run -it -p8080:8080

Slide 43

Slide 43 text

@mraible Build with Docker: Jib Get Jibby with it! mvn verify jib:build Or build directly to your Docker daemon mvn verify jib:dockerBuild https://github.com/GoogleContainerTools/jib

Slide 44

Slide 44 text

@mraible Build with Docker Micronaut uses Jib, but you must configure plugins Quarkus generates three Docker-related files Dockerfile.jvm Dockerfile.legacy-jar Dockerfile.native Dockerfile.native-distroless Quarkus + Jib mvn quarkus:add-extension -Dextensions="container-image-jib"

Slide 45

Slide 45 text

@mraible Build with Docker Spring Boot 2.3+ has built-in support mvn spring-boot:build-image Uses layered JARs for for faster builds dependencies snapshot-dependencies resources application https://spring.io/blog/2020/01/27/creating-docker-images-with-spring-boot-2-3-0-m1

Slide 46

Slide 46 text

@mraible Use Micronaut CLI mn create-app ... mvn package -Dpackaging=native-image gradle nativeImage gradle dockerBuildNative Go Native with GraalVM and Micronaut https://docs.micronaut.io/latest/guide/#graal

Slide 47

Slide 47 text

@mraible Go Native with GraalVM and Quarkus Create an executable without GraalVM installed mvn package -Pnative -Dquarkus.native.container-build=true Then, build the image docker build -f src/main/docker/Dockerfile.native -t \ . And run it docker run -it -p8080:8080 https://quarkus.io/guides/building-native-image

Slide 48

Slide 48 text

@mraible Use start.spring.io to get plugins and profiles org.springframework.boot spring-boot-maven-plugin ${repackage.classifier} paketobuildpacks/builder:tiny true org.springframework.experimental spring-aot-maven-plugin ${spring-native.version} Go Native with GraalVM and Spring Boot

Slide 49

Slide 49 text

@mraible Go Native with GraalVM and Spring Boot Add milestone repositories to your pom.xml spring-milestones Spring Milestones https://repo.spring.io/milestone spring-milestones Spring Milestones https://repo.spring.io/milestone

Slide 50

Slide 50 text

@mraible Go Native with GraalVM and Spring Boot Add Spring Native dependency org.springframework.experimental spring-native 0.10.4 Build the native application mvn spring-boot:build-image

Slide 51

Slide 51 text

@mraible How we fixed the Okta Spring Boot Starter https://youtu.be/8vY-9tXlCW4

Slide 52

Slide 52 text

@mraible Native Startup Performance Milliseconds 0 15 30 45 60 October 7, 2021 46.8 19 24 Micronaut Quarkus Spring Boot

Slide 53

Slide 53 text

@mraible Native Memory Used (MB) Milliseconds 0 25 50 75 100 October 7, 2021 82 34 62 Micronaut Quarkus Spring Boot

Slide 54

Slide 54 text

@mraible Tests Run on a 2019 MacBook Pro

Slide 55

Slide 55 text

@mraible Demo Time! https://github.com/oktadev/native-java-examples

Slide 56

Slide 56 text

Community

Slide 57

Slide 57 text

@mraible Stack Overflow Tags 0 32500 65000 97500 130000 October 7, 2021 111,521 2,011 1,205 Micronaut Quarkus Spring Boot

Slide 58

Slide 58 text

@mraible GitHub Stars 0 18750 37500 56250 75000 October 7, 2021 57,600 8,600 5,100 Micronaut Quarkus Spring Boot

Slide 59

Slide 59 text

star-history.t9t.io/#micronaut-projects/micronaut-core&quarkusio/quarkus&spring-projects/spring-boot GitHub Star Growth

Slide 60

Slide 60 text

@mraible Jobs on Indeed (US) 0 3250 6500 9750 13000 October 7, 2021 10,532 178 136 Micronaut Quarkus Spring Boot

Slide 61

Slide 61 text

@mraible Twitter Followers 0 25000 50000 75000 100000 October 7, 2021 78,500 12,600 10,600 Micronaut Quarkus Spring Boot

Slide 62

Slide 62 text

Hot Web Frameworks https://hotframeworks.com

Slide 63

Slide 63 text

@mraible JHipster Support 🤓 Micronaut Blueprint - github.com/jhipster/generator-jhipster-micronaut - v1.0.2, 18 releases, 16 contributors, 382 commits // TODO: Micronaut 3, Reactive, Microservices, GraalVM native images Quarkus Blueprint - github.com/jhipster/generator-jhipster-quarkus - v2.0.0-beta.1, 6 releases, 16 contributors, 550 commits // TODO: Quarkus 2.3, Dev Services, Reactive, Microservices

Slide 64

Slide 64 text

https://developer.okta.com/blog/2021/01/20/reactive-java-microservices

Slide 65

Slide 65 text

https://developer.okta.com/blog/2020/08/17/micronaut-jhipster-heroku

Slide 66

Slide 66 text

https://developer.okta.com/blog/2021/03/08/jhipster-quarkus-oidc

Slide 67

Slide 67 text

Recommendations from Twitter https://twitter.com/mraible/status/1445753175978360832

Slide 68

Slide 68 text

@mraible Action!

Slide 69

Slide 69 text

developer.okta.com/blog/tags/java @oktadev

Slide 70

Slide 70 text

git clone https://github.com/oktadeveloper/okta-spring-webflux-react- example.git https://github.com/oktadev/native-java-examples Use the Source, Luke!

Slide 71

Slide 71 text

Thanks! Keep in Touch raibledesigns.com @mraible Presentations speakerdeck.com/mraible Code github.com/oktadev developer.okta.com

Slide 72

Slide 72 text

developer.okta.com