Giter VIP home page Giter VIP logo

auth0-java-reactive-examples's Introduction

Reactive Java REST API Examples: Micronaut, Quarkus, Spring Boot, and Helidon

This repository contains example OAuth 2.0 resource servers built with reactive versions of Micronaut, Quarkus, Spring Boot, and Helidon. See this demo script to learn how these apps were created.

Visit @oktadev/auth0-java-rest-api-examples for examples using the non-reactive versions of these frameworks.

Prerequisites: Java 21 with GraalVM and HTTPie.

Getting Started

Click the button below to start a new Gitpod development environment with this project:

Open in Gitpod

Or, if you'd rather try things locally, clone this repository:

git clone https://github.com/oktadev/auth0-java-reactive-examples.git

You will need a JDK with GraalVM and its native-image compiler. Using SDKMAN, run the following command and set it as the default:

sdk install java 21.0.2-graalce

Next, you'll need a free Auth0 developer account.

Install the Auth0 CLI and run auth0 login to connect it to your account.

Create an access token using Auth0's CLI:

auth0 test token -a https://<your-auth0-domain>/api/v2/ -s openid

Set the access token as a TOKEN environment variable in a terminal window.

TOKEN=eyJraWQiOiJYa2pXdjMzTDRBYU1ZSzNGM...

Change the following files for each framework to match your Auth0 domain:

  • Micronaut: micronaut/src/main/resources/application.properties
  • Quarkus: quarkus/src/main/resources/application.properties
  • Spring Boot: spring-boot/src/main/resources/application.properties
  • Helidon: helidon/src/main/resources/application.properties

You can start each app using its CLI, Gradle, or Maven. Note that you will only be able to start one at a time since they all run on port 8080.

  • Micronaut: ./gradlew run
  • Quarkus: quarkus dev
  • Spring Boot: ./gradlew bootRun
  • Helidon: helidon dev

Then, you can test them with an access token and HTTPie.

Use HTTPie to pass the JWT in as a bearer token in the Authorization header.

http :8080/hello Authorization:"Bearer $TOKEN"

You should see your email address printed to your terminal.

You can also build and run each example as a native app.

  • Micronaut: ./gradlew nativeCompile
  • Quarkus: quarkus build --native
  • Spring Boot: ./gradlew nativeCompile
  • Helidon: mvn package -Pnative-image

Then, start each app as a native executable.

  • Micronaut: ./build/native/nativeCompile/app
  • Quarkus: ./build/quarkus-1.0.0-SNAPSHOT-runner
  • Spring Boot: ./build/native/nativeCompile/spring-boot
  • Helidon: ./target/helidon

Links

This example uses the following open source libraries:

Help

Please post any questions as issues in this repo or on the Auth0 Community Forums.

License

Apache 2.0, see LICENSE.

auth0-java-reactive-examples's People

Contributors

deepu105 avatar dependabot[bot] avatar mraible avatar sdelamo avatar

Stargazers

 avatar  avatar

Watchers

 avatar

auth0-java-reactive-examples's Issues

Why are the reactive versions of Quarkus and Helidon so slow to start?

Quarkus Reactive takes 7x longer to start: 353ms vs 49.4.
Helidon SE takes 5x longer: 303.6ms vs 59.4.

Startup time

Imperative

M: (36 + 48 + 36 + 47 + 42) / 5 = 41.8
Q: (55 + 46 + 44 + 54 + 48) / 5 = 49.4
S: (67 + 70 + 65 + 66 + 54) / 5 = 64.4
H: (64 + 55 + 61 + 58 + 59) / 5 = 59.4

Reactive

M: (52 + 45 + 47 + 46 + 47) / 5 = 47.4
Q: (359 + 291 + 276 + 534 + 305) / 5 = 353
S: (55 + 72 + 62 + 52 + 52) / 5 = 58.6
H: (239 + 239 + 509 + 263 + 268) / 5 = 303.6

Imperative with Virtual Threads

Q: (44 + 38 + 46 + 43 + 45) / 5 = 43.2
S: (71 + 64 + 68 + 71 + 66) / 5 = 68

Steps to reproduce

Install GraalVM 21:

sdk install java 21.0.2-graalce

For imperative:

git clone https://github.com/oktadev/auth0-java-rest-api-examples
cd auth0-java-rest-api-examples
./build.sh
./start.sh

The last script takes an argument of micronaut, quarkus, spring-boot, or helidon.

For reactive:

git clone https://github.com/oktadev/auth0-java-reactive-examples
cd auth0-java-reactive-examples
./build.sh
./start.sh

For virtual threads:

cd auth0-java-rest-api-examples
git checkout virtual-threads
./build.sh
./start.sh

I only calculated the startup times for Quarkus and Spring Boot because they're the only apps modified in the virtual-threads branch.

Memory usage (in MB):

Imperative

Framework 0 requests 1 request 10K requests
Micronaut 53 63 102
Quarkus 37 47 51
Spring Boot 76 86 105
Helidon 82 92 69

Imperative with Virtual Threads

Framework 0 requests 1 request 10K requests
Quarkus 37 48 51
Spring Boot 76 87 102

Reactive

Framework 0 requests 1 request 10K requests
Micronaut 53 62 102
Quarkus 49 50 53
Spring Boot 75 107 174
Helidon 44 45 68

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.