Spring Web Essentials
Spring Web Essentials
Building modern web services with Spring Boot
About the Book
If you want to learn how to develop modern web applications with Spring, this book is for you. Part one covers using Spring to power secure, industrial-grade web services ready to support modern web applications built with Hypertext Markup Language (HTML) and JavaScript such as Angular, React, and Vue. In part two, we develop a more traditional server-side HTML web application.
Why this book and not some other Spring book on the market?
The first version of Spring came out in 2003 when Java lacked many of the capabilities that make it a great language today, like generics, annotations, and variable arguments. As the language brought more natural ways of doing things, Spring improved to take advantage of them. Strong backward compatibility is one of the five major design philosophies of Spring, but it also means there are new, older, and much older ways of doing things. Documenting all of them makes for thick books.
Second, older books don't cover the magic that is Spring Boot, which significantly simplifies configuring and running Spring applications. It's no longer an arduous task to get a Spring application up and running, so why should you learn how to do lots of unnecessary work? Finally, newer books cover Spring boot but often lack the level of detail needed to deploy real applications to production, including unit tests, bean validation, and security. This book presents a complete example leaving you ready to work on industrial-grade Spring applications.
As a teacher, my reading assignments often had a longer list of what to skip than what to read. I wrote this book to use in the classroom with a focus on current best practices covering what students need to know. We follow a test-driven, standards-based approach. The text is full of links to documentation and reference information for each new concept presented.
Table of Contents
-
-
1 Introduction
- Foreword
- Who should read this book?
- What you will need
- About the author
- Acknowledgements
- Opt-in to get updates
-
1 Introduction
-
Part One: Web Services For The Modern Age
-
2 Getting started
- Create a new Maven project using Spring Initializr
- Extract and open the project
- Make sure you can run your new application
- A closer look at the Maven Project Object Model (POM) file
- A closer look at the main Java application class
- A closer look at the JUnit test class
- Git committed!
- Accomplishments
-
3 Some context
- Web services
- Representational State Transfer (REST)
- More about HTTP
-
4 Our first application programming interface (API)
- The OpenAPI specification
- Why are specs important?
- The SpankinFresh blog API specification
- Create a new blog posting
- Return a Location header
- Accomplishments
-
5 Adding an object model
- Updated OpenAPI specification
- Create a blog post domain class
- Incorporate the BlogPost class into our API
- Accomplishments
-
6 Adding a database
- Add the project dependencies:
- Creating an integration test
- Constructing a proper location header
- Testing for a nonzero ID
- Convert BlogPost into an @Entity:
- Create a Spring JPA repository:
- Using our new JPA repository
- Have the controller automatically set the datePosted
- How the new dependency affects our controller
- Test your changes with Postman
- Accomplishments
-
7 Testing with mocks
- Configure our new class for mocking
- Using our mock bean
- Improving our test
- Accomplishments
-
8 Putting the RUD in CRUD
- Get all articles
- Get an article by ID
- Update an existing article
- Delete an existing article
- Accomplishments:
-
9 Property validation
- Add the project dependencies:
- Add bean validation constraints to BlogPost
- Test that validation errors result in a bad request status
- Update the controller to run validation
- Testing with Postman
- Customizing the validation errors response
- Accomplishments
-
10 Spring Profiles and external databases
- Setting up PostgreSQL
- Configuring Spring to use PostgreSQL
- Add PostgreSQL to our maven dependencies
- Create a PostgreSQL profile configuration
- Run our application using the Postgres profile
- Testing persistence after a restart
- Viewing our data in DBeaver
- Adding more realistic sample data
- Accomplishments
-
11 Connecting a Single Page Application (SPA)
- Getting our front-end running
- Adding CORS support
- Customizing the API for our web front end
- Using JdbcTempate to generate the table of contents
- Enabling Browse by Category in the navigation bar
- Getting articles for specific category working
- Accomplishments
-
12 More on JPA entity relationships
- Add an Author entity bean
- Add an Author JPA repository interface
- Add a controller and unit tests
- Relating Author to BlogPost
- Fixing our blog post tests
- Adding an Author controller
- Requiring blog posts to have an author
- Testing in Postman
- Checking our changes in the web application
- Adding more realistic sample data
- Accomplishments
-
13 Securing our API
- Before we begin
- Spring Security Primer
- OAuth and OpenID Connect Primer
- Testing API security
- Integrate Okta OIDC and OAuth2 into our web app
- Getting our unit tests running
- Disabling our integration tests
- Testing with Postman
- Test the secure version of our web application against the secure Spring application
- Accomplishments
-
2 Getting started
-
Part Two: Server-side Websites with Spring
-
14 More about models and views
- Models
- Views
- Adding our Maven dependencies
- Adding our first test
- Getting our first test working
- Viewing our work using a web browser
- Adding model data
- Using model data in our view
- Accomplishments
-
15 Improving our welcome page
- Adding blog articles to our welcome page
- Styling our website
- Rendering the content as Markdown
- Accomplishments
-
16 Finishing our website
- Providing a list of category names
- Table of contents
- Displaying the “All Articles” page
- A bit of refactoring
- Show articles by category name
- Show article by ID
- Accomplishments
-
17 Administering authors and content
- Coming soon!
-
18 Securing our administration screens
- Coming soon!
-
14 More about models and views
- Notes
The Leanpub 60 Day 100% Happiness Guarantee
Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.
Now, this is technically risky for us, since you'll have the book or course files either way. But we're so confident in our products and services, and in our authors and readers, that we're happy to offer a full money back guarantee for everything we sell.
You can only find out how good something is by trying it, and because of our 100% money back guarantee there's literally no risk to do so!
So, there's no reason not to click the Add to Cart button, is there?
See full terms...
Earn $8 on a $10 Purchase, and $16 on a $20 Purchase
We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.
(Yes, some authors have already earned much more than that on Leanpub.)
In fact, authors have earnedover $14 millionwriting, publishing and selling on Leanpub.
Learn more about writing on Leanpub
Free Updates. DRM Free.
If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).
Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.
Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.
Learn more about Leanpub's ebook formats and where to read them