Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Building a RESTful Web Service with Spring

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

Arrow left icon
Product type Paperback
Published in Oct 2015
Publisher
ISBN-13 9781785285714
Length 128 pages
Edition 1st Edition
Languages
Tools
Concepts
Arrow right icon
Author (1):
Arrow left icon
Ludovic Dewailly Ludovic Dewailly
Author Profile Icon Ludovic Dewailly
Ludovic Dewailly
Arrow right icon
View More author details
Toc

Our RESTful web service

One common piece of software in use in the hospitality industry is a property management system (careful readers will notice the unfortunate acronym for these systems). It allows automating the operations of hotels and B&Bs. For the purpose of this book, we will build such a system using Spring. Each component of this system will expose a RESTful API that will be consumed by a simple web interface.

Tip

Designing effective Application Programming Interfaces is a topic that deserves its own treaty. It is beyond the scope of this book to discuss these concerns in detail. The main characteristics that one should bear in mind when designing APIs are: ease of use, consistency, exposing as little as necessary, extensibility, and forward compatibility.

Architecture

Our property management system will be formed of the four components, as illustrated in the following figure:

Architecture

The four components are explained as follows:

  • Inventory Service: This component provides the necessary functionality to manage and describe rooms and room types.
  • Availability Service: This component lets users see what rooms are available on specific dates.
  • Booking Service: This component will be responsible for taking bookings. It will rely on the Inventory Service and Availability Service components to validate bookings.
  • Billing Service: Once a booking is made, this component will offer the ability to generate an invoice.

Data model

In this section, we will look at the data model that will support our web service. The following entity relationship diagram provides an overview of this model:

Data model

The entities that constitute our model are as follows:

  • Room: This object represents the physical rooms that are part of our hotel. Rooms have a name and a description as well as photos.
  • RoomCategory: Each room belongs to a category (for example, double room). Categories provide a description, and are linked to a pricing model.
  • Pricing: This object encapsulates how rooms are priced (for example, a fixed price, or a sliding price based on the number of guests).
  • Booking: The reservation of rooms is modeled on bookings. Bookings will capture the reserved room, dates, and contact details for guests.
  • Invoice: This provides invoices to guests upon booking. They contain the relevant information regarding the booking, and the amount to be settled.

The data access layer will be implemented using Object-Relational Mapping (ORM) with Hibernate 4.3.8.

Tip

We will not delve into the specificities of Hibernate ORM in this book. However, documentation is available on Hibernate.org at http://hibernate.org/orm/.

In addition, for the purpose of simplifying the development and testing of our web service, we will use an embedded H2 database.

Note

Documentation about H2 can be found at http://www.h2database.com.

Hibernate supports H2 out of the box, so no specific setup is required to use it as our embedded database.

Tip

While an embedded database is great for development, it is not fit for a production deployment.

You have been reading a chapter from
Building a RESTful Web Service with Spring
Published in: Oct 2015
Publisher:
ISBN-13: 9781785285714
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image