Full Stack Quarkus and React - Marc Nuri San Felix - E-Book

Full Stack Quarkus and React E-Book

Marc Nuri San Felix

0,0
29,99 €

-100%
Sammeln Sie Punkte in unserem Gutscheinprogramm und kaufen Sie E-Books und Hörbücher mit bis zu 100% Rabatt.
Mehr erfahren.
Beschreibung

React has established itself as one of the most popular and widely adopted frameworks thanks to its simple yet scalable app development abilities. Quarkus comes across as a fantastic alternative for backend development by boosting developer productivity with features such as pre-built integrations, application services, and more that bring a new, revolutionary developer experience to Java. To make the best use of both, this hands-on guide will help you get started with Quarkus and React to create and deploy an end-to-end web application.
This book is divided into three parts. In the first part, you’ll begin with an introduction to Quarkus and its features, learning how to bootstrap a Quarkus project from the ground up to create a tested and secure HTTP server for your backend. The second part focuses on the frontend, showing you how to create a React project from scratch to build the application’s user interface and integrate it with the Quarkus backend. The last part guides you through creating cluster configuration manifests and deploying them to Kubernetes as well as other alternatives, such as Fly.io.
By the end of this full stack development book, you’ll be confident in your skills to combine the robustness of both frameworks to create and deploy standalone, fully functional web applications.

Das E-Book können Sie in Legimi-Apps oder einer beliebigen App lesen, die das folgende Format unterstützen:

EPUB
MOBI

Seitenzahl: 398

Veröffentlichungsjahr: 2022

Bewertungen
0,0
0
0
0
0
0
Mehr Informationen
Mehr Informationen
Legimi prüft nicht, ob Rezensionen von Nutzern stammen, die den betreffenden Titel tatsächlich gekauft oder gelesen/gehört haben. Wir entfernen aber gefälschte Rezensionen.



Full Stack Quarkus and React

Hands-on full stack web development with Java, React, and Kubernetes

Marc Nuri San Felix

BIRMINGHAM—MUMBAI

Full Stack Quarkus and React

Copyright © 2022 Packt Publishing

All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.

Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing or its dealers and distributors, will be held liable for any damages caused or alleged to have been caused directly or indirectly by this book.

Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.

Group Product Manager: Pavan Ramchandani

Publishing Product Manager: Kushal Dave

Senior Editor: Mark D’Souza

Senior Content Development Editor: Rashi Dubey

Technical Editor: Simran Udasi

Copy Editor: Safis Editing

Project Coordinator: Sonam Pandey

Proofreader: Safis Editing

Indexer: Hemangini Bari

Production Designer: Joshua Misquitta

Marketing Coordinator: Anamika Singh

First published: November 2022

Production reference: 1041122

Published by Packt Publishing Ltd.

Livery Place

35 Livery Street

Birmingham

B3 2PB, UK.

ISBN 978-1-80056-273-8

www.packt.com

To Julia, for her unconditional support on this journey. To Aitana and Álex, hoping that one day you’ll read this book and it sparks your curiosity for computer science and technology.

– Marc Nuri San Felix

Foreword

I have known Marc Nuri for many years at Red Hat. As well as being an incredible person who is always willing to help when you’ve got a problem, Marc is always open to having a conversation about improving any piece of code he’s writing.

At Red Hat, he is doing a great job of creating tools that improve the experience of Java developers transitioning to containers and Kubernetes technology. I can’t think of anyone better qualified than Marc to teach you about Java and Kubernetes.

Marc is also an international speaker, and in his presentations he makes it clear why you should use something by including easy-to-understand examples that use a wide range of Java technologies, such as Maven/Gradle or Spring Boot/Quarkus.

In Full Stack Quarkus and React, you’ll learn how to develop a Java backend application using Quarkus, the new Kubernetes-native Java framework that helps you develop supersonic (starting in milliseconds) and subatomic (minimizing its memory footprint) Java applications. Beyond the basics of Quarkus, you’ll learn how to secure the backend – also known as making the application testable. As well as the backend, you’ll develop the frontend using React, and integrate with Quarkus. Finally, you’ll learn how to deploy the application in Kubernetes, the de-facto platform for releasing microservices, in just one step (no YAML) which is the developer’s dream.

Get ready to become a Supersonic Subatomic Java developer with this book.

Alex Soto - Java Champion, Director of Developer Experience at Red Hat

Contributors

About the author

Marc started his career as a freelance web application developer, creating and maintaining software for the transportation/courier industry. A few years ago, Marc started working as an employee for different companies, where he helped build scalable web applications for different industries (retail, procurement software, e-commerce, etc.). He is now a professional open source developer focused on the creation and maintenance of developer tools for Java developers and Kubernetes.

I want to thank the Packt team and everyone else who helped out and worked on making this book come true; it’s been quite a ride and a great team effort.

Special thanks to my family and everyone else who supported me and had the patience to be around me during this intense period.

About the reviewers

James Brooks is a full-stack developer with a wide range of professional experience. He’s worked on a Windows desktop app and embedded devices at General Atomics, enterprise web-based applications at J.B. Hunt, and Medicare pricing and US Tax Court contracts at Flexion.

He’s worked with a few Java frameworks and is a big fan of Quarkus. His day job sees him contributing to a React/Node application. You can check out his dev profile page at https://james.oranbrooks.com. After hours, he runs Hidden Gems Digital Marketing, a digital marketing agency based out of Fayetteville, AR, US. He has a passion for the craft of software development and approaches it from an engineering and quality mindset.

Marcus Melo is a software engineer passionate about delivering efficient and reliable solutions. He has a master’s degree in computer science and certifications such as AWS Cloud Practitioner, a Java Programmer certification (SCJP 6), Scrum Master Certified, and AZ-900 Azure Fundamentals. He has about 16 years of experience in Java programming and, recently, experience in Java frameworks, some Quarkus, SpringBoot, and Angular, using some design patterns and working with agile methodology (Scrum). In addition, he worked as a developer at BB Tecnologia e Serviços, a division responsible for developing software solutions for one of the biggest banks in Brazil and many other companies. He currently works at Adentis in Portugal.

Wagner Ricardo Wagner is a software architect, trained in information systems. With more than 15 years of experience in the software market, he has participated in several projects in Brazil, Uruguay, and Paraguay, focused on the tax and financial sector. He has experience in the cloud, Java, Node, Go, databases, Google Cloud, K8s, DDD, clean code, architecture and code design, change data capture, NoSQL, and so on.

My thanks are directed to God, my family, and my friends, who always supported me throughout the journey. Also, I couldn’t fail to mention Jean Pachla and Nícolas Tischler for always providing me with great challenges and opportunities for my career to grow.

Table of Contents

Preface

Part 1– Creating a Backend with Quarkus

1

Bootstrapping the Project

Technical requirements

What is Quarkus?

Setting up the work environment with IntelliJ IDEA

Bootstrapping a Quarkus application

Project structure and dependencies

Maven Wrapper

Maven project (pom.xml)

Source files

Development mode

Continuous testing

Packaging the application

Summary

Questions

2

Adding Persistence

Technical requirements

Data persistence in Quarkus

Adding dependencies to our project

Configuring Quarkus

Implementing the task manager data model

Deleting the bootstrapped example classes and files

Creating the task manager entities

Database tables resulting from the ORM entities

Loading the application’s initial data

Quarkus Dev Services

Summary

Questions

3

Creating the HTTP API

Technical requirements

Writing HTTP REST endpoints in Quarkus

Adding the required dependencies to our project

Writing a blocking synchronous endpoint

Writing a non-blocking asynchronous endpoint

Implementing the task manager business logic

UserService

ProjectService

TaskService

Exposing the task manager to the frontend

UserResource

ProjectResource

TaskResource

Dealing with service exceptions

Summary

Questions

4

Securing the Application

Technical requirements

Using JWT security in Quarkus

Adding the required dependencies

Implementing the task manager’s HTTP API security

Generating the key files

Configuring the application

Implementing the authentication service and login interface

Getting the logged-in user

Letting users change their password

Securing the HTTP resources

Summary

Questions

5

Testing Your Backend

Technical requirements

Testing in Quarkus

Adding the missing test dependency to our project

Testing the task manager

Configuring the application

Testing authentication

Testing the user-related features

Testing the project-related features

Testing the task-related features

Summary

Questions

6

Building a Native Image

Technical requirements

Building a native executable in Quarkus

Setting up GraalVM

Creating a native image for the task manager

Including application resources

Building the native image

Running the native image

Building the native image in a Docker container

Summary

Questions

Part 2– Creating a Frontend with React

7

Bootstrapping the React Project

Technical requirements

What is React?

Creating a React project

Directory structure

Adding routing

Adding the React Material UI component library

Adding state management

Creating the common layout

Creating the TopBar component

Creating the MainDrawer component

Managing the layout’s state

Creating the Layout component

Displaying a dummy page

Setting up the global store

Overriding the MUI theme

Setting up the application router

Putting it all together

Summary

Questions

8

Creating the Login Page

Technical requirements

Setting up the authentication workflow

Configuring Quarkus for React dev mode

Configuring React’s environments

Managing the frontend session

Creating the Login page

Adding a protected user management page

Defining a user API Redux slice using Redux Toolkit’s createApi function

Creating the Users page

Adding a link to the Users page in MainDrawer

Running the application

Summary

Questions

9

Creating the Main Application

Technical requirements

Adding user-specific features

Implementing a password change dialog

Adding a user icon to the top bar

Adding CRUD functionalities

Adding the project management features

Adding the task management features

Finalizing the application’s layout

Deleting the no longer needed files and running the application

Summary

Questions

10

Testing Your Frontend

Technical requirements

Testing frontend applications overview

Adding the required dependencies

Testing React components

Running the tests on IntelliJ

Testing the router

Testing helpers

Testing the application’s routes and navigation system

Testing the application’s features

Testing the auth-related features

Testing the task management-related features

Running the tests from the command line

Summary

Questions

11

Quarkus Integration

Technical requirements

Distributing the application as a monolith versus a microservice

Advantages of a microservice architecture

The monolithic approach

Configuring the Quarkus application to build the frontend

Creating an HTTP resource to serve the React application from Quarkus

Running the application

Configuring the native build

Including the frontend resources

Fixing GatewayResource for native compilation

Running the native application

Summary

Questions

Part 3– Deploying Your Application to the Cloud

12

Deploying Your Application to Kubernetes

Technical requirements

What is Kubernetes?

What is a container-based application?

Setting up a local cluster with minikube

Creating a container image

Creating an image repository in Docker Hub

Building a container image with Eclipse JKube

Pushing the container image to Docker Hub

Using Jib to build and push a container image without Docker

Creating the cluster configuration manifests

Adjusting the cluster manifests from the project’s pom.xml

Adjusting the cluster manifests using fragments

Creating the cluster configuration manifests with Eclipse JKube

Deploying the task manager to minikube

Summary

Questions

13

Deploying Your Application to Fly.io

Technical requirements

Introducing Fly.io

Configuring the project for Fly.io

Creating a Dockerfile for Fly.io

Setting up a Maven profile for Fly.io

Deploying the task manager

Creating a Fly.io account

Logging in to Fly.io

Creating a new application

Analyzing the fly.toml app configuration

Deploying the app

Summary

Questions

14

Creating a Continuous Integration Pipeline

Technical requirements

Introducing GitHub Actions

What is continuous integration?

What are continuous delivery and continuous deployment?

GitHub Actions overview

Creating and pushing the application into a GitHub repository

Generating a PAT

Initializing the local git repository

Creating a GitHub Actions pipeline

Summary

Questions

Appendix – Answers

Chapter 1

Chapter 2

Chapter 3

Chapter 4

Chapter 5

Chapter 6

Chapter 7

Chapter 8

Chapter 9

Chapter 10

Chapter 11

Chapter 12

Chapter 13

Chapter 14

Index

Other Books You May Enjoy

Preface

React has established itself as one of the most popular and widely adopted JavaScript libraries due to its simplistic yet scalable ability to create applications. Quarkus is a fantastic alternative for backend development by boosting developer productivity with features such as prebuilt integrations, application services, and more that bring a new revolutionary developer experience to Java.

This book provides hands-on experience to get started with creating and deploying an end-to-end web application with Quarkus and React. For a simpler understanding, the book has been divided into three main parts. In the first part, you will begin with a basic introduction to Quarkus and its features. You will be taught how to bootstrap a Quarkus project from scratch to create a secure, tested HTTP server for your backend. The second part focuses on the frontend; you will learn how to create a React project from scratch to build the application’s user interface and how to integrate it with the Quarkus backend. The last part shows you how to create cluster configuration manifests and how to deploy them into Kubernetes, along with other alternatives such as Fly.io.

By the end of the book, you will be confident in your skills to combine the robustness of both frameworks to create and deploy standalone, fully functional web applications.

Who this book is for

This book is for backend web developers who have at least some basic experience with Java and who would like to learn React to build full stack apps, by integrating it with a Quarkus-based backend. It is also for frontend web developers with at least some basic experience with JavaScript who would like to implement a backend in Quarkus, integrate it with their frontend, and create full stack web applications.

Basic knowledge of Java and JavaScript is recommended, but any developer experienced just with Java or JavaScript should be able to follow the backend and frontend parts with no problem.

What this book covers

Chapter 1, Bootstrapping the Project, introduces Quarkus and the tooling that will be used, and shows you how to bootstrap a project for an application that will be implemented throughout the book.

Chapter 2, Adding Persistence, shows how to implement a persistence layer in Quarkus using Hibernate and the Java Persistence API (JPA).

Chapter 3, Creating the HTTP API, explains how to create a service layer and use dependency injection to implement an HTTP API in Quarkus.

Chapter 4, Securing the Application, shows how to provide a security layer based on JSON web tokens (JWTs) to protect the HTTP API.

Chapter 5, Testing Your Backend, introduces the Quarkus testing framework and Quarkus Dev Services and explains how to use them to implement tests for your application.

Chapter 6, Building a Native Image, shows you how to create a native executable for your Quarkus application.

Chapter 7, Bootstrapping the React Project, introduces React and the libraries that will be used to implement the frontend part of the application, and shows you how to bootstrap the project.

Chapter 8, Creating the Login Page, explains how to implement the authorization infrastructure and how to create the login page for the frontend side of the application.

Chapter 9, Creating the Main Application, shows how to implement the core features of the application and how to consume the backend’s HTTP API.

Chapter 10, Testing Your Frontend, explains how to implement unit and integration tests for your frontend applications based on React.

Chapter 11, Quarkus Integration, shows how to integrate the frontend application with Quarkus.

Chapter 12, Deploying Your Application to Kubernetes, gives a quick overview of Kubernetes and explains how to deploy the application to a Minikube Kubernetes cluster.

Chapter 13, Deploying Your Application to Fly.io, shows you how to deploy the application to Fly.io and make it publicly available.

Chapter 14, Creating a Continuous Integration Pipeline, introduces GitHub Actions and explains how to create a continuous integration (CI) pipeline.

To get the most out of this book

Basic knowledge of Java and JavaScript is recommended, but any developer experienced just with Java or JavaScript should be able to follow the complete book with no problem.

You will need the latest Java JDK LTS version, the latest Node.js LTS version, and a working Docker environment.

If you are using the digital version of this book, we advise you to type the code yourself or access the code from the book’s GitHub repository (a link is available in the next section). Doing so will help you avoid any potential errors related to the copying and pasting of code.

Download the example code files

You can download the example code files for this book from GitHub at https://github.com/PacktPublishing/Full-Stack-Quarkus-and-React. If there’s an update to the code, it will be updated in the GitHub repository.

We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!

Download the color images

We also provide a PDF file that has color images of the screenshots and diagrams used in this book. You can download it here: https://packt.link/yoqoD.

Conventions used

There are a number of text conventions used throughout this book.

Code in text: Indicates code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles. Here is an example: “The project includes the .mvn directory, and the mvnw and mvnw.cmdexecutable files.”

A block of code is set as follows:

<dependency>   <groupId>io.quarkus</groupId>   <artifactId>quarkus-resteasy-reactive</artifactId> </dependency>

Any command-line input or output is written as follows:

./mvnw quarkus:dev

Bold: Indicates a new term, an important word, or words that you see on screen. For instance, words in menus or dialog boxes appear in bold. Here is an example: “For this, we need to create a new debug configuration from the Run | Edit Configurations menu.”

Tips or important notes

Appear like this.

Get in touch

Feedback from our readers is always welcome.

General feedback: If you have questions about any aspect of this book, email us at [email protected] and mention the book title in the subject of your message.

Errata: Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you have found a mistake in this book, we would be grateful if you would report this to us. Please visit www.packtpub.com/support/errata and fill in the form.

Piracy: If you come across any illegal copies of our works in any form on the internet, we would be grateful if you would provide us with the location address or website name. Please contact us at [email protected] with a link to the material.

If you are interested in becoming an author: If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, please visit authors.packtpub.com.

Download a free PDF copy of this book

Thanks for purchasing this book!

Do you like to read on the go but are unable to carry your print books everywhere?

Is your eBook purchase not compatible with the device of your choice?

Don’t worry, now with every Packt book you get a DRM-free PDF version of that book at no cost.

Read anywhere, any place, on any device. Search, copy, and paste code from your favorite technical books directly into your application.

The perks don’t stop there, you can get exclusive access to discounts, newsletters, and great free content in your inbox daily!

Follow these simple steps to get the benefits:

Scan the QR code or visit the link below:

https://packt.link/free-ebook/9781800562738

Submit your proof of purchaseThat’s it! We’ll send your free PDF and other benefits to your email directly

Part 1– Creating a Backend with Quarkus

This section focuses on the knowledge and skills required to implement a backend in Java by leveraging the Quarkus framework and its extensions. In this part, you will learn how to bootstrap a Quarkus project from scratch to create a secure, tested HTTP server for your backend.

In this part, we cover the following chapters:

Chapter 1, Bootstrapping the ProjectChapter 2, Adding PersistenceChapter 3, Creating the HTTP APIChapter 4, Securing the ApplicationChapter 5, Testing Your BackendChapter 6, Building a Native Image