100% found this document useful (3 votes)
64 views47 pages

PDF Pro RESTful APIs With Micronaut: Build Java-Based Microservices With REST, JSON, and XML, 2nd Edition Sanjay Patni Download

Microservices

Uploaded by

hbibhaosu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (3 votes)
64 views47 pages

PDF Pro RESTful APIs With Micronaut: Build Java-Based Microservices With REST, JSON, and XML, 2nd Edition Sanjay Patni Download

Microservices

Uploaded by

hbibhaosu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 47

Download the full version of the ebook at

https://ebookmass.com

Pro RESTful APIs with Micronaut: Build Java-


Based Microservices with REST, JSON, and XML,
2nd Edition Sanjay Patni

https://ebookmass.com/product/pro-restful-apis-
with-micronaut-build-java-based-microservices-
with-rest-json-and-xml-2nd-edition-sanjay-patni/

Explore and download more ebook at https://ebookmass.com


Recommended digital products (PDF, EPUB, MOBI) that
you can download immediately if you are interested.

Pro RESTful APIs with Micronaut: Build Java-Based


Microservices with REST, JSON, and XML 2 / converted
Edition Sanjay Patni
https://ebookmass.com/product/pro-restful-apis-with-micronaut-build-
java-based-microservices-with-rest-json-and-xml-2-converted-edition-
sanjay-patni/
testbankdeal.com

Coding Clean, Reliable, and Safe REST APIs with ASP.NET


Core 8: Develop Robust Minimal APIs with .NET 8 Anthony
Giretti
https://ebookmass.com/product/coding-clean-reliable-and-safe-rest-
apis-with-asp-net-core-8-develop-robust-minimal-apis-with-
net-8-anthony-giretti/
testbankdeal.com

Coding Clean, Reliable, and Safe REST APIs with ASP.NET


Core 8 1st Edition Anthony Giretti

https://ebookmass.com/product/coding-clean-reliable-and-safe-rest-
apis-with-asp-net-core-8-1st-edition-anthony-giretti/

testbankdeal.com

Data Engineering with AWS: Acquire the skills to design


and build AWS-based data transformation pipelines like a
pro 2nd Edition Eagar
https://ebookmass.com/product/data-engineering-with-aws-acquire-the-
skills-to-design-and-build-aws-based-data-transformation-pipelines-
like-a-pro-2nd-edition-eagar/
testbankdeal.com
Beginning Cloud Native Development with MicroProfile,
Jakarta EE, and Kubernetes: Java DevOps for Building and
Deploying Microservices-based Applications 1st Edition
Tarun Telang
https://ebookmass.com/product/beginning-cloud-native-development-with-
microprofile-jakarta-ee-and-kubernetes-java-devops-for-building-and-
deploying-microservices-based-applications-1st-edition-tarun-telang/
testbankdeal.com

Beginning Spring Boot 3: Build Dynamic Cloud-Native Java


Applications and Microservices - Second Edition K. Siva
Prasad Reddy
https://ebookmass.com/product/beginning-spring-boot-3-build-dynamic-
cloud-native-java-applications-and-microservices-second-edition-k-
siva-prasad-reddy/
testbankdeal.com

Postman for API Testing: A Beginner's Guide: Learn to test


APIs like a pro with Postman with Real-World Examples and
Step-by-Step Guidance Parvin
https://ebookmass.com/product/postman-for-api-testing-a-beginners-
guide-learn-to-test-apis-like-a-pro-with-postman-with-real-world-
examples-and-step-by-step-guidance-parvin/
testbankdeal.com

Simple and Efficient Programming with C#: Skills to Build


Applications with Visual Studio and .NET 2nd Edition
Vaskaran Sarcar
https://ebookmass.com/product/simple-and-efficient-programming-with-c-
skills-to-build-applications-with-visual-studio-and-net-2nd-edition-
vaskaran-sarcar/
testbankdeal.com

Simple and Efficient Programming with C# : Skills to Build


Applications with Visual Studio and .NET 2nd Edition
Vaskaran Sarcar
https://ebookmass.com/product/simple-and-efficient-programming-with-c-
skills-to-build-applications-with-visual-studio-and-net-2nd-edition-
vaskaran-sarcar-2/
testbankdeal.com
Pro RESTful APIs
with Micronaut
Build Java-Based Microservices
with REST, JSON, and XML
Second Edition

Sanjay Patni
Pro RESTful APIs with Micronaut: Build Java-Based Microservices with
REST, JSON, and XML
Sanjay Patni
Santa Clara, CA, USA

ISBN-13 (pbk): 978-1-4842-9199-3 ISBN-13 (electronic): 978-1-4842-9200-6


https://doi.org/10.1007/978-1-4842-9200-6
Copyright © 2023 by Sanjay Patni
This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or
part of the material is concerned, specifically the rights of translation, reprinting, reuse of
illustrations, recitation, broadcasting, reproduction on microfilms or in any other physical way,
and transmission or information storage and retrieval, electronic adaptation, computer software,
or by similar or dissimilar methodology now known or hereafter developed.
Trademarked names, logos, and images may appear in this book. Rather than use a trademark
symbol with every occurrence of a trademarked name, logo, or image we use the names, logos,
and images only in an editorial fashion and to the benefit of the trademark owner, with no
intention of infringement of the trademark.
The use in this publication of trade names, trademarks, service marks, and similar terms, even if
they are not identified as such, is not to be taken as an expression of opinion as to whether or not
they are subject to proprietary rights.
While the advice and information in this book are believed to be true and accurate at the date of
publication, neither the authors nor the editors nor the publisher can accept any legal
responsibility for any errors or omissions that may be made. The publisher makes no warranty,
express or implied, with respect to the material contained herein.
Managing Director, Apress Media LLC: Welmoed Spahr
Acquisitions Editor: Susan McDermott
Development Editor: Laura Berendson
Coordinating Editor: Jessica Vakili
Distributed to the book trade worldwide by Springer Science+Business Media New York,
233 Spring Street, 6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax (201) 348-4505,
e-mail [email protected], or visit www.springeronline.com. Apress Media, LLC is a
California LLC and the sole member (owner) is Springer Science + Business Media Finance Inc
(SSBM Finance Inc). SSBM Finance Inc is a Delaware corporation.
For information on translations, please e-mail [email protected]; for
reprint, paperback, or audio rights, please e-mail [email protected].
Apress titles may be purchased in bulk for academic, corporate, or promotional use. eBook
versions and licenses are also available for most titles. For more information, reference our Print
and eBook Bulk Sales web page at http://www.apress.com/bulk-sales.
Any source code or other supplementary material referenced by the author in this book is
available to readers on the Github repository: https://github.com/Apress/Pro-RESTful-APIs-
with-Micronaut. For more detailed information, please visit http://www.apress.com/
source-code.
Printed on acid-free paper
I would like to thank everyone at Apress who I’ve worked
closely with. Thanks to the reviewers; their in-depth reviews
helped the quality of the book. A heartfelt thanks goes to my
wife, Veena, for her tireless and unconditional support that
helped me work on this book. A huge thanks goes to my
father, Ajit Kumar Patni, and my mother, Late Basantidevi,
for their selfless support that helped me reach
where I am today.
Table of Contents
About the Author���������������������������������������������������������������������������������xi

About the Technical Reviewer�����������������������������������������������������������xiii

Introduction����������������������������������������������������������������������������������������xv

Chapter 1: Fundamentals of RESTful APIs��������������������������������������������1


Abstract�����������������������������������������������������������������������������������������������������������������1
SOAP vs. REST������������������������������������������������������������������������������������������������������4
Web Architectural Style�����������������������������������������������������������������������������������������7
Client-Server���������������������������������������������������������������������������������������������������7
Uniform Resource Interface�����������������������������������������������������������������������������8
Layered System�����������������������������������������������������������������������������������������������8
Caching������������������������������������������������������������������������������������������������������������8
Stateless����������������������������������������������������������������������������������������������������������9
Code on Demand���������������������������������������������������������������������������������������������9
HATEOAS��������������������������������������������������������������������������������������������������������10
What Is REST?�����������������������������������������������������������������������������������������������������11
REST Basics���������������������������������������������������������������������������������������������������12
REST Fundamentals��������������������������������������������������������������������������������������13
Summary������������������������������������������������������������������������������������������������������������15

v
Table of Contents

Chapter 2: Micronaut��������������������������������������������������������������������������17
Abstract���������������������������������������������������������������������������������������������������������������17
Comparison of Micronaut with Spring Boot��������������������������������������������������������18
Ease of Installation����������������������������������������������������������������������������������������18
Natively Cloud Enabled����������������������������������������������������������������������������������19
Serverless Functions�������������������������������������������������������������������������������������19
Application Configuration������������������������������������������������������������������������������20
Messaging System Support���������������������������������������������������������������������������21
Security���������������������������������������������������������������������������������������������������������22
Caching����������������������������������������������������������������������������������������������������������23
Management and Monitoring������������������������������������������������������������������������23
API Portfolio��������������������������������������������������������������������������������������������������������24
Online Flight��������������������������������������������������������������������������������������������������24
Message��������������������������������������������������������������������������������������������������������25
Software��������������������������������������������������������������������������������������������������������������26
Micronaut������������������������������������������������������������������������������������������������������26
JDK 11�����������������������������������������������������������������������������������������������������������27
POSTMAN������������������������������������������������������������������������������������������������������27
CURL��������������������������������������������������������������������������������������������������������������27
IDE�����������������������������������������������������������������������������������������������������������������27
Maven������������������������������������������������������������������������������������������������������������28
Setting Up an IDE������������������������������������������������������������������������������������������������28
Configuring Visual Studio Code���������������������������������������������������������������������29
Summary������������������������������������������������������������������������������������������������������������30

Chapter 3: Introduction: XML and JSON���������������������������������������������31


Abstract���������������������������������������������������������������������������������������������������������������31
What Is XML?������������������������������������������������������������������������������������������������������31
XML Comments���������������������������������������������������������������������������������������������33

vi
Table of Contents

Why Is XML Important?���������������������������������������������������������������������������������34


How Can You Use XML?���������������������������������������������������������������������������������35
Pros and Cons of XML�����������������������������������������������������������������������������������35
What Is JSON?����������������������������������������������������������������������������������������������������36
JSON Syntax��������������������������������������������������������������������������������������������������36
Why Is JSON Important?��������������������������������������������������������������������������������38
How Can You Use JSON?�������������������������������������������������������������������������������40
Pros and Cons of JSON����������������������������������������������������������������������������������40
XML and JSON Comparison���������������������������������������������������������������������������41
Implementing APIs to Return XML and JSON Messages�������������������������������������42
Summary������������������������������������������������������������������������������������������������������������49

Chapter 4: API Design and Modeling��������������������������������������������������51


Abstract���������������������������������������������������������������������������������������������������������������51
API Design Strategies������������������������������������������������������������������������������������������51
API Creation Process and Methodology��������������������������������������������������������������54
Process����������������������������������������������������������������������������������������������������������54
API Methodology��������������������������������������������������������������������������������������������54
Domain Analysis or API Description���������������������������������������������������������������55
Architecture Design���������������������������������������������������������������������������������������56
Prototyping����������������������������������������������������������������������������������������������������57
Implementation���������������������������������������������������������������������������������������������58
Publish�����������������������������������������������������������������������������������������������������������58
API Modeling��������������������������������������������������������������������������������������������������58
Comparison of API Modeling��������������������������������������������������������������������������60
In summary���������������������������������������������������������������������������������������������������61
Best Practices�����������������������������������������������������������������������������������������������������62
Keep Your Base URL Simple and Intuitive������������������������������������������������������62
Error Handling�����������������������������������������������������������������������������������������������64

vii
Table of Contents

Error Code������������������������������������������������������������������������������������������������������65
Versioning������������������������������������������������������������������������������������������������������66
Partial Response��������������������������������������������������������������������������������������������67
Pagination������������������������������������������������������������������������������������������������������67
Multiple Formats�������������������������������������������������������������������������������������������68
API Façade�����������������������������������������������������������������������������������������������������68
API Solution Architecture������������������������������������������������������������������������������������69
Mobile Solutions��������������������������������������������������������������������������������������������70
Cloud Solutions����������������������������������������������������������������������������������������������70
Web Solutions������������������������������������������������������������������������������������������������70
Integration Solutions�������������������������������������������������������������������������������������71
Multichannel Solutions����������������������������������������������������������������������������������71
Smart TV Solutions����������������������������������������������������������������������������������������71
Internet of Things������������������������������������������������������������������������������������������71
Stakeholders in API Solutions�����������������������������������������������������������������������������72
API Providers�������������������������������������������������������������������������������������������������72
API Consumers����������������������������������������������������������������������������������������������72
End Users������������������������������������������������������������������������������������������������������72
API Modeling�������������������������������������������������������������������������������������������������������72
Summary������������������������������������������������������������������������������������������������������������80

Chapter 5: API Portfolio and Framework��������������������������������������������81


Abstract���������������������������������������������������������������������������������������������������������������81
API Portfolio Architecture������������������������������������������������������������������������������������81
Requirements������������������������������������������������������������������������������������������������82
Consistency���������������������������������������������������������������������������������������������������82
Reuse�������������������������������������������������������������������������������������������������������������82
Customization������������������������������������������������������������������������������������������������83
Discoverability�����������������������������������������������������������������������������������������������83

viii
Table of Contents

Longevity�������������������������������������������������������������������������������������������������������83
How Do We Enforce These Requirements—Governance?����������������������������83
Consistency���������������������������������������������������������������������������������������������������84
Reuse�������������������������������������������������������������������������������������������������������������84
Customization������������������������������������������������������������������������������������������������84
Discoverability�����������������������������������������������������������������������������������������������84
Change Management������������������������������������������������������������������������������������85
API Framework����������������������������������������������������������������������������������������������������85
Process APIs: Services Layer�������������������������������������������������������������������������86
System APIs: Data Access Object������������������������������������������������������������������87
Experience APIs: API Façade��������������������������������������������������������������������������87
Services Layer Implementation���������������������������������������������������������������������87
Summary������������������������������������������������������������������������������������������������������������95

Chapter 6: API Platform and Data Handler�����������������������������������������97


Abstract���������������������������������������������������������������������������������������������������������������97
API Platform Architecture������������������������������������������������������������������������������������97
Why Do We Need an API Platform?���������������������������������������������������������������������98
So What Is an API Platform?��������������������������������������������������������������������������������98
So Which Capabilities Does the API Platform Have?�������������������������������������������99
API Development Platform����������������������������������������������������������������������������������99
API Runtime Platform����������������������������������������������������������������������������������������101
API Engagement Platform���������������������������������������������������������������������������������101
How Is an API Platform Organized? What Is the Architecture of the API
Platform?����������������������������������������������������������������������������������������������������������102
How Does the API Architecture Fit in the Surrounding Technical
Architecture of an Enterprise?��������������������������������������������������������������������������103
Data Handler�����������������������������������������������������������������������������������������������������105
Data Access Object�������������������������������������������������������������������������������������������105

ix
Visit https://ebookmass.com
now to explore a rich
collection of eBooks and enjoy
exciting offers!
Table of Contents

Command Query Responsibility Segregation (CQRS)����������������������������������������106


SQL Development Process��������������������������������������������������������������������������������106
NoSQL Process��������������������������������������������������������������������������������������������������107
Do I Have to Choose Between SQL and NoSQL?�����������������������������������������������107
Why a Single REST API?������������������������������������������������������������������������������������107
Summary����������������������������������������������������������������������������������������������������������126

Chapter 7: API Management and CORS��������������������������������������������127


Abstract�������������������������������������������������������������������������������������������������������������127
Façade��������������������������������������������������������������������������������������������������������������127
Façade Pattern��������������������������������������������������������������������������������������������������127
API Façade��������������������������������������������������������������������������������������������������������128
API Management�����������������������������������������������������������������������������������������������130
API Life Cycle����������������������������������������������������������������������������������������������������131
API Retirement��������������������������������������������������������������������������������������������������132
API Monetization�����������������������������������������������������������������������������������������������133
Cross-Origin Resource Sharing (CORS)�������������������������������������������������������������134
Summary����������������������������������������������������������������������������������������������������������134

Index�������������������������������������������������������������������������������������������������135

x
About the Author
Sanjay Patni is a results-focused technologist
with extensive experience in aligning
innovative technology solutions with business
needs to optimize manual steps in the
business processes and improving operational
efficiency.
At Oracle, he has worked with the Fusion
Apps Product development team, where he
has identified opportunities for automation
of programs related to Fusion Apps codeline management. This involved
delivery of GA releases for patching, as well as codelines for ongoing
demo, development, and testing. He conceptualized and developed self-
service UX for codeline requests and auditing, reducing manual steps by
80%. He also rolled out 12 sprints of codeline creation, automating about
100+ manual steps involving integration with other subsystems using
technologies like automation workflow and RESTful APIs.
Prior to joining Oracle, he spent 15+ years in the software industry,
defining and delivering key initiatives across different industry sectors.
His responsibilities included innovation, requirement, analysis, technical
architecture, design, and agile software development of web-based
enterprise products and solutions. He pioneered innovative usage of
Java in building business applications and received an award from Sun
Microsystems. This helped improve feedback for Java APIs for Enterprise
in building business application software using Java. He has diverse
experience in Application Architecture to include UX, Distributed Systems,
Cloud and DevOps.

xi
About the Author

He has worked as a visiting technical instructor or mentor and


conducted classes or training on RESTful APIs design and integration.
He has a strong educational background in computer science with a
master’s from IIT, Roorkee, India.

xii
About the Technical Reviewer
Massimo Nardone has more than 22 years
of experience in security, web and mobile
development, cloud, and IT architecture. His
true IT passions are security and Android.
He has been programming and teaching
how to program with Android, Perl, PHP, Java,
VB, Python, C/C++, and MySQL for more than
20 years.
He holds a master of science degree in
computing science from the University of
Salerno, Italy.
He has worked as a project manager, software engineer, research
engineer, chief security architect, information security manager, PCI/
SCADA auditor, and senior lead IT security/cloud/SCADA architect for
many years.
His technical skills include security, Android, cloud, Java, MySQL,
Drupal, Cobol, Perl, web and mobile development, MongoDB, D3, Joomla,
Couchbase, C/C++, WebGL, Python, Pro Rails, Django CMS, Jekyll,
Scratch, etc.
He currently works as Chief Information Security Officer (CISO) for
Cargotec Oyj.
He worked as visiting lecturer and supervisor for exercises at the
Networking Laboratory of the Helsinki University of Technology (Aalto
University). He holds four international patents (PKI, SIP, SAML, and
Proxy areas).
Massimo has reviewed more than 40 IT books for different publishing
companies, and he is the coauthor of Pro Android Games (Apress, 2015).

xiii
Introduction
Databases, websites, and business applications need to exchange data.
This is accomplished by defining standard data formats such as Extensible
Markup Language (XML) or JavaScript Object Notation (JSON), as
well as transfer protocols or web services such as the Simple Object
Access Protocol (SOAP) or the more popular Representational State
Transfer (REST). Developers often have to design their own Application
Programming Interfaces (APIs) to make applications work while
integrating specific business logic around operating systems or servers.
This book introduces these concepts with a focus on the RESTful APIs.
This book introduces the data exchange mechanism and common data
formats. For web exchange, you will learn the HTTP protocol, including
how to use XML. This book compares SOAP and REST and then covers
the concepts of stateless transfer. It introduces software API design and
best design practices. The second half of the book focuses on RESTful APIs
design and implementations that follow the Micronaut and Java API for
RESTful Web Services. You will learn how to build and consume Micronaut
services using JSON and XML and integrate RESTful APIs with different
data sources like relational databases and NoSQL databases through
hands-on exercises. You will apply these best practices to complete a
design review of publicly available APIs with a small-scale software system
in order to design and implement RESTful APIs.
This book is intended for software developers who use data in projects.
It is also useful for data professionals who need to understand the methods
of data exchange and how to interact with business applications. Java
programming experience is required for the exercises.

xv
Introduction

Topics include

• Data exchange and web services

• SOAP vs. REST, state vs. stateless

• XML vs. JSON

• Introduction to API design: REST and Micronaut

• API design practices

• Designing RESTful APIs

• Building RESTful APIs

• Interacting with RDBMS (MySQL)

• Consuming RESTful APIs (i.e., JSON, XML)

xvi
CHAPTER 1

Fundamentals
of RESTful APIs
Abstract
APIs are not new. They’ve served as interfaces that enable applications
to communicate with each other for decades. But the role of APIs has
changed dramatically in the last few years. Innovative companies
have discovered that APIs can be used as an interface to the business,
allowing them to monetize digital assets, extend their value proposition
with partner-delivered capabilities, and connect to customers across
channels and devices. When you create an API, you are allowing others
within or outside of your organization to make use of your service or
product to create new applications, attract customers, or expand their
business. Internal APIs enhance the productivity of development teams
by maximizing reusability and enforcing consistency in new applications.
Public APIs can add value to your business by allowing third-party
developers to enhance your services or bring their customers to you. As
developers find new applications for your services and data, a network
effect occurs, delivering significant bottom-line business impact. For
example, Expedia opened up their travel booking services to partners
through an API to launch the Expedia Affiliate Network, building a new
revenue stream that now contributes $2B in annual revenue. Salesforce

© Sanjay Patni 2023 1


S. Patni, Pro RESTful APIs with Micronaut, https://doi.org/10.1007/978-1-4842-9200-6_1
Chapter 1 Fundamentals of RESTful APIs

released APIs to enable partners to extend the capabilities of their platform


and now generates half of their annual revenue through those APIs, which
could be SOAP based (JAX-WS) and, more recently, RESTful (JAX-RS),
Spring Boot, and now Micronaut.
A SOAP web service depends upon a number of technologies (such
as UDDI, WSDL, SOAP, HTTP) and protocols to transport and transform
data between a service provider and the consumer and can be created
with JAX-WS.
Later, Roy Fielding (in the year 2000) presented his doctoral
dissertation, “Architectural Styles and the Design of Network-based
Software Architecture.” He coined the term “REST,” an architectural
style for distributed hypermedia systems. Put simply, REST (short for
REpresentational State Transfer) is an architectural style defined to help
create and organize distributed systems. The keyword from that definition
should be “style,” because an important aspect of REST (and which is one
of the main reasons books like this one exist) is that it is an architectural
style—not a guideline, not a standard, or anything that would imply that
there are a set of hard rules to follow in order to end up having a RESTful
architecture.
In this chapter, I’ll be covering REST fundamentals, SOAP vs. REST, and
web architectural style to provide a solid foundation and better prepare
you for what you’ll see in later chapters.
The main idea behind REST is that a distributed system, organized
RESTfully, will improve in the following areas:

• Performance: The communication style proposed by


REST is meant to be efficient and simple, allowing a
performance boost on systems that adopt it.

• Scalability of component interaction: Any distributed


system should be able to handle this aspect well
enough, and the simple interaction proposed by REST
greatly allows for this.

2
Chapter 1 Fundamentals of RESTful APIs

• Simplicity of interface: A simple interface allows for


simpler interactions between systems, which in turn
can grant benefits like the ones previously mentioned.

• Modifiability of components: The distributed nature of


the system, and the separation of concerns proposed by
REST (more on this in a bit), allows for components to
be modified independently of each other at a minimum
cost and risk.

• Portability: REST is technology and language agnostic,


meaning that it can be implemented and consumed
by any type of technology (there are some constraints
that I’ll go over in a bit, but no specific technology is
enforced).

• Reliability: The stateless constraint proposed by REST


(more on this later) allows for the easier recovery of a
system after failure.

• Visibility: Again, the stateless constraint proposed has


the added full state of said request (this will become
clear once I talk about the constraints in a bit). From
this list, some direct benefits can be extrapolated. A
component-centric design allows you to make systems
that are very fault tolerant. Having the failure of one
component not affect the entire stability of the system
is a great benefit for any system. Interconnecting
components is quite easy, minimizing the risks when
adding new features or scaling up or down. A system
designed with REST in mind will be accessible to a
wider audience, thanks to its portability (as described
earlier). With a generic interface, the system can be
used by a wider range of developers. In order to achieve

3
Visit https://ebookmass.com
now to explore a rich
collection of eBooks and enjoy
exciting offers!
Chapter 1 Fundamentals of RESTful APIs

these properties and benefits, a set of constraints were


added to REST to help define a uniform connector
interface. REST is not suggested to use when you need
to enforce a strict contract between a client and a
server and when performing transactions that involve
multiple calls.

SOAP vs. REST


Table 1-1 has a comparison between SOAP and REST with an example of
use cases each can support.

4
Table 1-1. SOAP vs. REST comparison
Topic SOAP REST

Origin SOAP (Simple Object Access Protocol) was created in REST (Representational State Transfer) was
1998 by Dave Winer et al. in collaboration with Microsoft. created in 2000 by Roy Fielding at UC, Irvine.
Developed by a large software company, this protocol Developed in an academic environment, this
addresses the goal of addressing the needs of the protocol embraces the philosophy of the open
enterprise market Web
Basic Makes data available as services (verb + noun), for Makes data available as resources (nouns), for
Concept example, “getUser” or “PayInvoice” example, “user” or “invoice”
Pros Follows a formal enterprise approach Follows the philosophy of the open Web
Works on top of any communication protocol, even Relatively easy to implement and maintain
Chapter 1

asynchronously Clearly separates client and server implementations


Information about objects is communicated to clients Communication isn’t controlled by a single entity
Security and authorization are part of the protocol Information can be stored by the client to prevent
Can be fully described using WSDL multiple calls
Can return data in multiple formats (JSON, XML, etc.)
Cons Spends a lot of bandwidth communicating metadata Only works on top of the HTTP protocol
Hard to implement and is unpopular among web and Hard to enforce authorization and security on top
mobile developers of it

5
Fundamentals of RESTful APIs

(continued)
Random documents with unrelated
content Scribd suggests to you:
With sands of sleep, from slumber’s sea.
I try my best awake to stay,
But I am tired out with play;
“I’ll never see him!” mother says,
And mother tells the truth—always!

—Marie Van Vorst

BILLY BINKS

(d art) (pl ace) (d ance)


st art le f ace pr ance

c ast les (eight) (st ar)


n eigh ed f ar ther
h urr y
p urr (sm ile) (r oof)
m ile h oof
(f elt)
m elt waul (r oar)
s oar
pres ent ly trav eled
en e mies
en tered fin ished
for tune
blazed hor ri ble
sau cers
di rect ly front
prom ise
ter ri ble ter ri fied
broom
dis ap peared re mem ber

Once upon a time a little boy named Billy Binks set out to seek his
fortune. He traveled alone for many a weary mile, but at last he met
a little gray pony.
“Where are you going, Billy Binks?” neighed the pony.
“I am going to seek my fortune,” said Billy Binks.
“May I go, too?”
“If I take you, will you help me win my fortune?”
“Yes.”
“How?”
“I will carry you on my back and kick all your enemies with my hard
hoofs.”
“Very well, you may come along.”
Then they went on a little farther and met a cow.
“Where are you going, Billy Binks?” mooed the cow.
“I am going to seek my fortune,” answered Billy Binks.
“May I go, too?”
“If I take you, will you help me win my fortune?”
“Yes.”
“How?”
“I will moo, and toss your enemies on my sharp horns.”
“Very well, you may come.”
When they had walked on a little farther they met a dog.
“Where are you going, Billy Binks?” barked the dog.
“I am going to seek my fortune,” answered Billy Binks.
“May I go, too?”
“If I take you, will you help me win my fortune?”
“Yes.”
“How?”
“I will bark, and bite your enemies with my sharp teeth.”
“Very well, you may come.”
After walking a little farther they met a cat.
“Where are you going, Billy Binks?” mewed the cat.
“I am going to seek my fortune,” answered Billy Binks.
“May I go, too?”
“If I take you, will you help me win my fortune?”
“Yes.”
“How?”
“I will purr, and scratch your enemies with my sharp claws.”
“Very well, you may come.”
They continued their journey and presently met a raven.
“Where are you going, Billy Binks?” croaked the raven.
“I am going to seek my fortune.”
“May I go, too?”
“If I take you, will you help me win my fortune?”
“Yes.”
“How?”
“I will croak, and peck your enemies’ eyes out with my sharp
beak.”
“Very well, you may come.”
On and on they walked till at last they entered a deep, dark wood.
All day they journeyed through this forest, which grew denser and
darker as night came on.
“We are near a clearing in this wood,” croaked the raven, who had
been soaring above the treetops. “Let us keep right on.”
Suddenly all were startled by a bright light, the brightest any of
them had ever seen. It flashed out through the trees directly in front
of them. It fairly dazzled and blinded them. Then it as suddenly
disappeared, and left them standing terrified in the pitch-black
darkness of the night.
Again the light flashed out, and again disappeared.
“What can it be?” asked Billy Binks, hoarsely, as soon as he could
find his voice.
“Perhaps it is a lamp,” mewed the cat.
“No, it is too bright for a lamp,” answered Billy Binks.
“It might be a house on fire,” barked the dog.
“No, if it were, we could see the light all the time; and besides,
there is no house here. I have flown this way before,” answered the
raven.
“It may be a lighthouse,” said Billy Binks.
“No,” replied the raven, “the sea is miles from here. You all keep
still while I fly over the treetops and find out what it is.”
Billy Binks and his animal friends kept ever so quiet, while the
raven flew up and quickly disappeared in the darkness. It seemed
hours before he returned.
“Oh, my friends,” croaked the raven, alighting in their midst at last,
“you never saw such a sight! There’s the most horrible, monstrous
hob-goblin over there in the clearing. He has a nose as long as a
broomstick—”
“Oh! Oh! Oh!” cried Billy Binks and his friends.
“—Eyes as big as saucers and as green as the sea—”
“Oh! Oh! Oh!” cried Billy Binks and his friends.
“—And a mouth big enough to swallow us all!”
“Oh! Oh! Oh!” cried Billy Binks and his friends.
“He has a great fire blazing among some rocks. That is the light
you saw. When he walks in front of it you cannot see the light. That
is why you thought it disappeared.”
“I see! I see! I see!” said Billy Binks and his friends.
“He is busy melting gold, and he has piles of gold and jewels
hidden in his cave—”
“Ah, ha!” laughed Billy Binks, as he climbed bravely upon his gray
pony.
“His cave is full of nice plump field mice—”
“Mew! Mew!” cried the cat, as she scrambled up behind Billy
Binks.
“In the bushes back of the cave live many rabbits—”
“Bow-wow!” barked the dog, as he bounded toward Billy Binks.
“Near the cave is a large green meadow, with the sweetest grass
and the coolest brook in the world—”
“Moo! Moo!” lowed the cow, as she, too, hurried up beside Billy
Binks.
“And there is a tall tree that will make a fine home for me,” finished
the raven, as she flew over Billy Binks’s head.
“Come on, friends,” whispered Billy Binks, boldly. “It is time to win
my fortune. Remember you have all promised to help me.”
“Yes, yes, I’ll help. And I think I see my fortune, too,” answered
each of the animals, now as bold as Billy Binks.
Softly, quietly, and slowly they crept through the forest. Presently
they came to the clearing. There stood the ugly, black hob-goblin,
bending over his fire. His back was turned toward them.

“Now!” shouted Billy Binks, and they all rushed at the terrible
monster.
The raven dashed into his face and pecked at his large green
eyes.
The cat scratched great gashes in his long nose.
The dog bit him, and the horse kicked him.
The enraged cow rushed upon him with lowered head, caught him
on her horns, and tossed him as high as the treetops.
Then the cow began to bellow.
The dog began to howl.
The cat began to waul.
The raven began to caw.
The pony began to prance.
And Billy Binks began to shout with all his might.
Such a frightful din that old hob-goblin had never heard! He picked
himself up from the sharp rocks where he had fallen, and dashed
away with might and main through the forest. If he hasn’t stopped,
he is running still.
“Ho, ho!” cried Billy Binks, springing from the gray pony and
running to the mouth of the cave. “This heap of gold and this pile of
jewels will do for my fortune. If you carry them safely home for me,
Pony, I will build you a beautiful stable, and you shall have a full crib
of oats before you all the rest of your life. That will be your fortune.”
“This cave, full of good, plump mice, is my fortune,” called the cat,
as she pounced on the first unlucky mouse.
“All these rabbits shall be my fortune,” barked the dog, as he set
off in hot haste after a fleeing bunny.
“And this green meadow is my fortune,” mooed the cow, as she
began to crop the sweet grass.
“Who could have a better fortune than this?” croaked the raven,
flying to the top of a tall tree.
So Billy Binks said “Good-by” to his friends, and left them each
with his fortune. He quickly bagged the gold and jewels, threw them
across the pony’s back, and mounting, hurried off homeward.
The pony smelled oats all the way, while Billy Binks saw castles
and lands on all sides.
Some Things to think About
WHEN THE LITTLE BOY RAN AWAY

(s ist er) (r oam) (under)


tw ist ed f oam ing th under

wan der ed ech o par ents

aw ful trun dle


When the little boy ran away from home,
The birds in the tree-top knew,
And they all sang, “Stay!” but he wandered away
Under the skies of blue.
And the wind came whispering from the tree,
“Follow me, follow me!”
And it sang him a song that was soft and sweet
And scattered the roses before his feet
That day, that day,
When the little boy ran away.

The violets whispered, “Your eyes are blue


And lovely and bright to see,
And so are mine, and I’m kin to you,
So dwell in the light with me.”
But the little boy laughed, while the wind in glee
Sang, “Follow, follow me!”
And the wind called the clouds from their home in the skies
And said to the violet, “Shut your eyes!”
That day, that day,
When the little boy ran away.

Then the wind played leapfrog over the hills


And twisted each leaf and limb;
And all the rivers and all the rills
Were foaming mad with him;
And ’twas dark as the darkest night could be,
But still came the wind’s voice, “Follow me!”
And over the mountain and up from the hollow
Came echoing voices with, “Follow him; follow!”
That awful day,
When the little boy ran away.

Then the little boy cried, “Let me go, let me go!”


For a scared, scared boy was he.
But the thunder growled from a black cloud, “No!”
And the wind roared, “Follow me!”
And an old gray owl from a tree-top flew,
Saying: “Who are you-oo? Who are you-oo?”
And the little boy sobbed, “I’m lost away!
And I want to go home where my parents stay.”
O, the awful day
When the little boy ran away!

Then the moon looked out from a cloud and said:


“Are you sorry you ran away?
If I light you home to your trundle bed,
Will you stay, little boy, will you stay?”
And the little boy promised—and cried and cried—
He never would leave his mother’s side,
And the moonlight led him over the plain;
And his mother welcomed him home again.
But, O, what a day
When the little boy ran away!
HOW THE BEAN GOT ITS BLACK SEAM
(ea gle) (r ope) sew ed
ea ger h ope
hul lo
(h ush) (m ean)
cr ush b ean cru el

mo ment gur gling tor rent

quar rel four both er

coun try pour ing a las

in stant ly

Once upon a time there was a poor old woman living in a village of
a far country. She had gathered some beans and was making ready
to cook them. She built a fire of sticks, but, as these were damp, they
did not burn well. So she thrust in a handful of dry straw. Now the
flames leaped up, and the sticks snapped and crackled in the blaze.
A live red coal flew out of the fire, fell on the ground beside a
straw, and lay there smoking. Just then a bean dropped from the pot
which the old woman was filling, rolled away, and came to rest close
to the coal and the straw.
“Hullo, Mr. Coal,” said the straw. “How you smoke! Are you
frightened? Where did you come from?”
“I just sprang out of that fire,” answered the coal. “Had I not
jumped just as I did, I should now be nothing but ashes. My, look at
that blaze!”

“I, too, jumped in the nick of time,” spoke up the bean. “That cruel
old woman was just pouring me into the pot when I leaped over the
edge, and here I am.”
“Yes, here you are, silly thing,” broke out the coal and the straw
together. “But what are you going to do? As soon as the old woman
turns around she will spy you, then back you’ll go into the pot. It’s
hotter now than when you left it.”
“Don’t bother about me; think of yourselves,” answered the bean,
angrily. “When the old woman picks me up, she’ll tread on you, Mr.
Coal, and crush your life out. And you, Mrs. Straw, she’ll stick into
the blaze. It’s hotter there than in the pot.”
“Come, come,” said the straw, softly, “let’s not quarrel. Let’s be
friends and stick together. Perhaps we can save ourselves yet.”
“You are quite right, Mrs. Straw,” said the coal.
The bean said nothing, but she listened eagerly to the plans of the
two others. These soon agreed to travel together to a far country,
where they hoped to find their fortune. They set out without delay,
and the bean rolled along behind.
Soon the three travelers came to a little gurgling brook. It seemed
to them a mighty rushing and roaring torrent.
“Oh, dear, what shall we do now?” asked the bean, speaking for
the first time since the journey began. “We can never get across
these awful waters. Hear them thunder down the rocky cliffs!”
“Don’t worry, little Bean,” said the straw, proudly. “I’ll help you and
Mr. Coal across in a twinkling.”
Thereupon the straw laid herself across the stream. She was just
long enough to reach from bank to bank.
“Now walk over the bridge, Mr. Coal and Miss Bean,” called the
straw.
The coal hastened on to the straw bridge while the bean watched
in wonder. All went well until the middle of the stream was reached,
when the bridge bent so low under the weight of the coal and the
waters thundered so loudly that the coal stopped in fright.
The coal stood still for only a moment. But, alas, that was a
moment too long.
The dry straw smoked, burst into a tiny flame, and broke in two.
Down fell the coal into the water below and was instantly drowned.
The burning straw bridge also fell into the water, which put out the
flames, and the two pieces of straw went floating away down stream.

All this the little bean saw, watching safely from the bank. And she
thought it the funniest thing that ever happened. So she laughed and
she laughed—until she burst!
This would have been the end of little Miss Bean, had not a tailor
passed that way just then. He was sorry for the poor bean, so he
picked up the two parts tenderly, and quickly sewed them together.
But the thread that he used was black. And ever since that time
some beans have a black seam around them.
FRIENDS

(tw ist) ferns com fort ed


wh ist ling North gent ians

North Wind came whistling through the wood


Where the tender, sweet things grew—
The tall fair ferns and the maiden hair,
And the gentle gentians blue.
“It’s very cold! Are we growing old?”
They sighed, “What shall we do?”

The sigh went up to the loving leaves.


“We must help,” they whispered low.
“They are frightened and weak, O brave old trees!
But we love you well, you know.”
And the trees said, “We are strong—make haste!
Down to the darlings go.”

So the leaves went floating, floating down,


All yellow, and brown, and red,
And the frail little trembling, thankful things
Lay still, and were comforted.
And the blue sky smiled through the bare old trees,
Down on their soft warm beds.

—L. G. Warner.
HELP ONE ANOTHER

(m outh) splen did (m ount ain)


s outh f ount ain

“Help one another,” the snowflakes said,


As they cuddled down in their fleecy bed.
“One of us here would not be felt,
One of us here would quickly melt;
But I’ll help you, and you help me,
And then what a splendid drift there’ll be.”

“Help one another,” the maple spray


Said to its fellow leaves one day;
“The sun would wither me here alone,
Long enough ere the day is gone;
But I’ll help you, and you help me,
And then what a splendid shade there’ll be.”

You might also like