Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Building a RESTful Web Service with Spring
Building a RESTful Web Service with Spring

Building a RESTful Web Service with Spring: A hands-on guide to building an enterprise-grade, scalable RESTful web service using the Spring Framework

eBook
€13.98 €19.99
Paperback
€24.99
Subscription
Free Trial
Renews at €18.99p/m

What do you get with a Packt Subscription?

Free for first 7 days. €18.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing
Table of content icon View table of contents Preview book icon Preview Book

Building a RESTful Web Service with Spring

Chapter 2. Building RESTful Web Services with Maven and Gradle

As mentioned in the previous chapter, we will build a sample property management system as a RESTful web service. Before we dig into the implementation, let's first take a look at how the service will be put together. In this chapter, we will discuss the following topics:

  • Building a RESTful web service with Apache Maven
  • Building a RESTful web service with Gradle
  • Structuring our property management web service
  • Running and debugging a Spring-based web service

Apache Maven

Maven is an open-source software project management tool. It was born out of the need to simplify Ant-based builds and it favors convention over configuration. In more concrete terms, it offers out of the box support for typical workflows, such as building Java web applications, provided one follows its conventions. However, customizing the build process can prove challenging, and many of its detractors point this design choice out as the main motivation for not using Maven.

Note

More information on Maven can be found at https://maven.apache.org.

While Maven offers many features, they are beyond the scope of this chapter. We will focus on its support for building Java web applications.

The following POM (Project Object Model) file illustrates how a project can be declared with Maven (in a file called pom.xml):

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven...

Gradle

Gradle is a project automation tool that borrows a lot of concepts from Maven. It differs from Maven in using a Groovy-based declarative syntax instead of XML.

Note

Read more about Gradle at https://gradle.org. And, head over to http://www.groovy-lang.org for an introduction to Groovy.

Gradle has become a popular alternative to Maven for its flexibility and neater declarative syntax, while still offering powerful dependency management. We will take a quick look at dependency management in the next section.

Dependency management in Gradle

Gradle offers dependency resolution. It can be set up to use Maven's Central Repository. Let's consider a sample Gradle build (in a file called build.gradle):

apply plugin: 'java'

repositories {
    mavenCentral()
}

We instructed Gradle that we want to build a Java project and that the dependencies should be fetched from Maven's Central Repository. Now, we can simply declare the dependencies we require as follows:

dependencies...

The structure of our sample web service

In Chapter 1, A Few Basics, we decomposed this application into four components:

  • Inventory Service
  • Availability Service
  • Booking Service
  • Billing Service

One approach would be to build our project as a single module and have the code of these four services together.

While it makes the setup quite straightforward, it might impede our ability to deploy these components individually, should it be required for scalability purposes (refer to Chapter 10, Scaling a RESTful Web Service, for discussions on scalability). Instead, we will organize each service into its own individual module.

For the purpose of this section, we will focus on Maven. Our project will be made up of six separate Maven modules:

  • common: This module contains common code and the Hibernate setup that is to be used
  • inventory: This is the inventory service implementation
  • availability: This is the availability service implementation
  • booking: This is the booking service implementation
  • billing: This is...

Developing RESTful web services

In this section, we will provide a few tips to effectively develop Spring-based RESTful web services.

Working with your favorite IDE

Maven and Gradle are well-supported tools and most integrated development environments, or IDEs, provide a way to import such projects. For example, with IntelliJ IDEA, our sample web service project can be imported by selecting the menu options File | Open. Once imported, the project will be shown as follows:

Working with your favorite IDE

With the project imported, we can start implementing our property management system web service. Before we do so, however, let's discuss how to execute our service.

Note

Both Eclipse and NetBeans also offer support for Maven and Gradle (via plugins).

Making services executable

With Maven or Gradle, it is possible to package the service in a WAR format. However, to quickly start and debug the application during development, we are going to implement an executable Java class. With Spring Boot it is easily achieved via the...

Summary

We saw how to set up a Maven or Gradle build to support the implementation of a RESTful web service. It is now time to start implementing our sample web service. The next chapter will introduce the first REST endpoint.

Left arrow icon Right arrow icon

Description

REST is an architectural style that tackles the challenges of building scalable web services. In today’s connected world, APIs have taken a central role on the web. APIs provide the fabric through which systems interact, and REST has become synonymous with APIs. The depth, breadth, and ease of use of Spring makes it one of the most attractive frameworks in the Java ecosystem. Marrying the two technologies is therefore a very natural choice. This book takes you through the design of RESTful web services and leverages the Spring Framework to implement these services. Starting from the basics of the philosophy behind REST, you’ll go through the steps of designing and implementing an enterprise-grade RESTful web service. Taking a practical approach, each chapter provides code samples that you can apply to your own circumstances. This book goes beyond the use of Spring and explores approaches to tackle resilience, security, and scalability concerns. You’ll learn techniques to deal with security in Spring and discover how to implement unit and integration test strategies. Finally, the book ends by walking you through building a Java client for your RESTful web service, along with some scaling techniques for it.

Who is this book for?

This book is intended for those who want to learn to build RESTful web services with the Spring Framework. To make best use of the code samples included in the book, you should have a basic knowledge of the Java language. Previous experience with the Spring Framework would also help you get up and running quickly.

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Oct 14, 2015
Length: 128 pages
Edition : 1st
Language : English
ISBN-13 : 9781785285714
Vendor :
Pivotal
Languages :
Concepts :
Tools :

What do you get with a Packt Subscription?

Free for first 7 days. €18.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing

Product Details

Publication date : Oct 14, 2015
Length: 128 pages
Edition : 1st
Language : English
ISBN-13 : 9781785285714
Vendor :
Pivotal
Languages :
Concepts :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
€18.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
€189.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts
€264.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total 88.97
Spring Boot Cookbook
€26.99
Building a RESTful Web Service with Spring
€24.99
SPRING COOKBOOK
€36.99
Total 88.97 Stars icon

Table of Contents

11 Chapters
1. A Few Basics Chevron down icon Chevron up icon
2. Building RESTful Web Services with Maven and Gradle Chevron down icon Chevron up icon
3. The First Endpoint Chevron down icon Chevron up icon
4. Data Representation Chevron down icon Chevron up icon
5. CRUD Operations in REST Chevron down icon Chevron up icon
6. Performance Chevron down icon Chevron up icon
7. Dealing with Security Chevron down icon Chevron up icon
8. Testing RESTful Web Services Chevron down icon Chevron up icon
9. Building a REST Client Chevron down icon Chevron up icon
10. Scaling a RESTful Web Service Chevron down icon Chevron up icon
Index Chevron down icon Chevron up icon

Customer reviews

Top Reviews
Rating distribution
Full star icon Full star icon Full star icon Half star icon Empty star icon 3.7
(15 Ratings)
5 star 33.3%
4 star 33.3%
3 star 13.3%
2 star 13.3%
1 star 6.7%
Filter icon Filter
Top Reviews

Filter reviews by




David R. Willson Apr 27, 2016
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This is a very information dense book. I was prepared to be disappointed when it arrived because it was so thin. I was instead very pleased. The book is a walkthrough of a little RESTful web services application automating a hotel booking agency. The code examples downloadable from PACKT Published have all worked without any bugs and I have found only one insignificant typo in the book. Highly recommend.
Amazon Verified review Amazon
Emerald Dsouza Oct 10, 2016
Full star icon Full star icon Full star icon Full star icon Full star icon 5
The book is great for quick read before an interview for rest web services as it touches on the main concepts of code modularization, scaling, caching and security, implementing clients and server side code. You need to know spring but it's gives you a complete picture of all the moving parts. Also recommended if you are new to rest web services and are assigned to a development team that is implementing them.
Amazon Verified review Amazon
Ruben Cepeda Jan 03, 2016
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I was really pleased with the pace of the book that the breath of knowledge on how to use Spring's RESTful web service. It had a really good example application. I've been creating and maintaining RESTful web services for over 4 years now and this book has expanded even my knowledge.
Amazon Verified review Amazon
Patcho Dec 15, 2015
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This is an excellent introduction to building web services with the Spring framework. I have built web services before but not with Spring so this was a easy way to get introduced to all of its facets. The book walks the reader through the thought process of building a web service and sample code is a nice compliment. The chapters on performance and security stand out as these are what most developers leave out completely or don't think of until the end of the development cycle.The sample code is well written and helps the reader to gain some real world knowledge on how to approach creating web services. This is a introductory book so it will give you the full foundations. It also has a section on scaling web services along with complimentary technologies like Redis and Hazelcast which helps to introduce the reader to thinking more about the architecture and infrastructure rather than focusing just on the application.An excellent book all round.
Amazon Verified review Amazon
Charlie C. Dec 12, 2015
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Overall the book strikes a great balance in both it’s length and content. The problem with many tutorials/books is that they either give you so little information that in real “enterprise” situations you are completely lost or the information provided is so in depth you both can’t understand and lose interest.Topics covered are diverse and each is gently introduced and implemented in the demo hotel property management system.Testing, performance, build tools, security, scaling and client applications are all covered. This will not leave you an expert in all these areas but gives a great overview and I have found myself coming back to the book as a reference.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

What is included in a Packt subscription? Chevron down icon Chevron up icon

A subscription provides you with full access to view all Packt and licnesed content online, this includes exclusive access to Early Access titles. Depending on the tier chosen you can also earn credits and discounts to use for owning content

How can I cancel my subscription? Chevron down icon Chevron up icon

To cancel your subscription with us simply go to the account page - found in the top right of the page or at https://subscription.packtpub.com/my-account/subscription - From here you will see the ‘cancel subscription’ button in the grey box with your subscription information in.

What are credits? Chevron down icon Chevron up icon

Credits can be earned from reading 40 section of any title within the payment cycle - a month starting from the day of subscription payment. You also earn a Credit every month if you subscribe to our annual or 18 month plans. Credits can be used to buy books DRM free, the same way that you would pay for a book. Your credits can be found in the subscription homepage - subscription.packtpub.com - clicking on ‘the my’ library dropdown and selecting ‘credits’.

What happens if an Early Access Course is cancelled? Chevron down icon Chevron up icon

Projects are rarely cancelled, but sometimes it's unavoidable. If an Early Access course is cancelled or excessively delayed, you can exchange your purchase for another course. For further details, please contact us here.

Where can I send feedback about an Early Access title? Chevron down icon Chevron up icon

If you have any feedback about the product you're reading, or Early Access in general, then please fill out a contact form here and we'll make sure the feedback gets to the right team. 

Can I download the code files for Early Access titles? Chevron down icon Chevron up icon

We try to ensure that all books in Early Access have code available to use, download, and fork on GitHub. This helps us be more agile in the development of the book, and helps keep the often changing code base of new versions and new technologies as up to date as possible. Unfortunately, however, there will be rare cases when it is not possible for us to have downloadable code samples available until publication.

When we publish the book, the code files will also be available to download from the Packt website.

How accurate is the publication date? Chevron down icon Chevron up icon

The publication date is as accurate as we can be at any point in the project. Unfortunately, delays can happen. Often those delays are out of our control, such as changes to the technology code base or delays in the tech release. We do our best to give you an accurate estimate of the publication date at any given time, and as more chapters are delivered, the more accurate the delivery date will become.

How will I know when new chapters are ready? Chevron down icon Chevron up icon

We'll let you know every time there has been an update to a course that you've bought in Early Access. You'll get an email to let you know there has been a new chapter, or a change to a previous chapter. The new chapters are automatically added to your account, so you can also check back there any time you're ready and download or read them online.

I am a Packt subscriber, do I get Early Access? Chevron down icon Chevron up icon

Yes, all Early Access content is fully available through your subscription. You will need to have a paid for or active trial subscription in order to access all titles.

How is Early Access delivered? Chevron down icon Chevron up icon

Early Access is currently only available as a PDF or through our online reader. As we make changes or add new chapters, the files in your Packt account will be updated so you can download them again or view them online immediately.

How do I buy Early Access content? Chevron down icon Chevron up icon

Early Access is a way of us getting our content to you quicker, but the method of buying the Early Access course is still the same. Just find the course you want to buy, go through the check-out steps, and you’ll get a confirmation email from us with information and a link to the relevant Early Access courses.

What is Early Access? Chevron down icon Chevron up icon

Keeping up to date with the latest technology is difficult; new versions, new frameworks, new techniques. This feature gives you a head-start to our content, as it's being created. With Early Access you'll receive each chapter as it's written, and get regular updates throughout the product's development, as well as the final course as soon as it's ready.We created Early Access as a means of giving you the information you need, as soon as it's available. As we go through the process of developing a course, 99% of it can be ready but we can't publish until that last 1% falls in to place. Early Access helps to unlock the potential of our content early, to help you start your learning when you need it most. You not only get access to every chapter as it's delivered, edited, and updated, but you'll also get the finalized, DRM-free product to download in any format you want when it's published. As a member of Packt, you'll also be eligible for our exclusive offers, including a free course every day, and discounts on new and popular titles.