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 eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

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 : 9781785283192
Vendor :
Pivotal
Languages :
Concepts :
Tools :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : Oct 14, 2015
Length: 128 pages
Edition : 1st
Language : English
ISBN-13 : 9781785283192
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

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.