0% found this document useful (0 votes)
11 views

Pro RESTful APIs with Micronaut: Build Java-Based Microservices with REST, JSON, and XML 2 / converted Edition Sanjay Patni - Read the ebook online or download it for a complete experience

The document promotes the book 'Pro RESTful APIs with Micronaut' by Sanjay Patni, which focuses on building Java-based microservices using REST, JSON, and XML. It provides an overview of API design, data exchange mechanisms, and best practices for creating RESTful APIs, specifically using the Micronaut framework. The document also includes links to download the book and explore additional related resources and textbooks.

Uploaded by

lousisyaqud
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

Pro RESTful APIs with Micronaut: Build Java-Based Microservices with REST, JSON, and XML 2 / converted Edition Sanjay Patni - Read the ebook online or download it for a complete experience

The document promotes the book 'Pro RESTful APIs with Micronaut' by Sanjay Patni, which focuses on building Java-based microservices using REST, JSON, and XML. It provides an overview of API design, data exchange mechanisms, and best practices for creating RESTful APIs, specifically using the Micronaut framework. The document also includes links to download the book and explore additional related resources and textbooks.

Uploaded by

lousisyaqud
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 55

Visit ebookmass.

com to download the full version and


explore more ebook or textbook

Pro RESTful APIs with Micronaut: Build Java-Based


Microservices with REST, JSON, and XML 2 /
converted Edition Sanjay Patni

_____ Click the link below to download _____


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

Explore and download more ebook or textbook at ebookmass.com


Here are some recommended products that we believe you will be
interested in. You can click the link to download.

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/

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/

Learn Microservices with Spring Boot 3 3rd / converted


Edition Moises Macero Garcia

https://ebookmass.com/product/learn-microservices-with-spring-
boot-3-3rd-converted-edition-moises-macero-garcia/

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/
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/

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/

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/

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/

Learning Java: Beginning programming with java for dummies


Bach

https://ebookmass.com/product/learning-java-beginning-programming-
with-java-for-dummies-bach/
Sanjay Patni

Pro RESTful APIs with Micronaut


Build Java-Based Microservices with REST,
JSON, and XML
2nd ed.
Sanjay Patni
Santa Clara, CA, USA

ISBN 978-1-4842-9199-3 e-ISBN 978-1-4842-9200-6


https://doi.org/10.1007/978-1-4842-9200-6

© Sanjay Patni 2017, 2023

This work is subject to copyright. All rights are solely and exclusively
licensed 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.

The use of general descriptive names, registered names, trademarks,


service marks, etc. in this publication does not imply, even in the
absence of a specific statement, that such names are exempt from the
relevant protective laws and regulations and therefore free for general
use.

The publisher, the authors, and the editors are safe to assume that the
advice and information in this book are believed to be true and accurate
at the date of publication. Neither the publisher nor the authors or the
editors give a warranty, expressed or implied, with respect to the
material contained herein or for any errors or omissions that may have
been made. The publisher remains neutral with regard to jurisdictional
claims in published maps and institutional affiliations.

This Apress imprint is published by the registered company APress


Media, LLC, part of Springer Nature.
The registered company address is: 1 New York Plaza, New York, NY
10004, U.S.A.
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.
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.
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)
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.
Table of Contents
Chapter 1:​Fundamentals of RESTful APIs
Abstract
SOAP vs.​REST
Web Architectural Style
Client-Server
Uniform Resource Interface
Layered System
Caching
Stateless
Code on Demand
HATEOAS
What Is REST?​
REST Basics
REST Fundamentals
Summary
Chapter 2:​Micronaut
Abstract
Comparison of Micronaut with Spring Boot
Ease of Installation
Natively Cloud Enabled
Serverless Functions
Application Configuration
Messaging System Support
Security
Caching
Management and Monitoring
API Portfolio
Online Flight
Message
Software
Micronaut
JDK 11
POSTMAN
CURL
IDE
Maven
Setting Up an IDE
Configuring Visual Studio Code
Summary
Chapter 3:​Introduction:​XML and JSON
Abstract
What Is XML?​
XML Comments
Why Is XML Important?​
How Can You Use XML?​
Pros and Cons of XML
What Is JSON?​
JSON Syntax
Why Is JSON Important?​
How Can You Use JSON?​
Pros and Cons of JSON
Visit https://ebookmass.com today to explore
a vast collection of ebooks across various
genres, available in popular formats like
PDF, EPUB, and MOBI, fully compatible with
all devices. Enjoy a seamless reading
experience and effortlessly download high-
quality materials in just a few simple steps.
Plus, don’t miss out on exciting offers that
let you access a wealth of knowledge at the
best prices!
XML and JSON Comparison
Implementing APIs to Return XML and JSON Messages
Summary
Chapter 4:​API Design and Modeling
Abstract
API Design Strategies
API Creation Process and Methodology
Process
API Methodology
Domain Analysis or API Description
Architecture Design
Prototyping
Implementation
Publish
API Modeling
Comparison of API Modeling
In summary
Best Practices
Keep Your Base URL Simple and Intuitive
Error Handling
Error Code
Versioning
Partial Response
Pagination
Multiple Formats
API Façade
API Solution Architecture
Mobile Solutions
Cloud Solutions
Web Solutions
Integration Solutions
Multichannel Solutions
Smart TV Solutions
Internet of Things
Stakeholders in API Solutions
API Providers
API Consumers
End Users
API Modeling
Summary
Chapter 5:​API Portfolio and Framework
Abstract
API Portfolio Architecture
Requirements
Consistency
Reuse
Customization
Discoverability
Longevity
How Do We Enforce These Requirements—Governance?​
Consistency
Reuse
Customization
Discoverability
Change Management
API Framework
Process APIs:​Services Layer
System APIs:​Data Access Object
Experience APIs:​API Façade
Services Layer Implementation
Summary
Chapter 6:​API Platform and Data Handler
Abstract
API Platform Architecture
Why Do We Need an API Platform?​
So What Is an API Platform?​
So Which Capabilities Does the API Platform Have?​
API Development Platform
API Runtime Platform
API Engagement Platform
How Is an API Platform Organized?​What Is the Architecture of
the API Platform?​
How Does the API Architecture Fit in the Surrounding Technical
Architecture of an Enterprise?​
Data Handler
Data Access Object
Command Query Responsibility Segregation (CQRS)
SQL Development Process
NoSQL Process
Do I Have to Choose Between SQL and NoSQL?​
Why a Single REST API?​
Summary
Chapter 7:​API Management and CORS
Abstract
Façade
Façade Pattern
API Façade
API Management
API Life Cycle
API Retirement
API Monetization
Cross-Origin Resource Sharing (CORS)
Summary
Index
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.
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.
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).
© The Author(s), under exclusive license to APress Media, LLC, part of Springer Nature 2023
S. Patni, Pro RESTful APIs with Micronaut
https://doi.org/10.1007/978-1-4842-9200-6_1

1. Fundamentals of RESTful APIs


Sanjay Patni1

(1) Santa Clara, CA, USA

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 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.
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 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.
Table 1-1 SOAP vs. REST comparison

Topic SOAP REST


SOAP (Simple Object Access Protocol) was created in 1998 REST (Representational State Transfer) was
by Dave Winer et al. in collaboration with Microsoft. created in 2000 by Roy Fielding at UC, Irvine.
Origin Developed by a large software company, this protocol Developed in an academic environment, this
addresses the goal of addressing the needs of the enterprise protocol embraces the philosophy of the open
market Web
Basic Makes data available as services (verb + noun), for example, Makes data available as resources (nouns), for
Concept “getUser” or “PayInvoice” example, “user” or “invoice”
Topic SOAP REST
Follows the philosophy of the open Web
Relatively easy to implement and maintain
Follows a formal enterprise approach
Clearly separates client and server
Works on top of any communication protocol, even implementations
asynchronously
Pros Communication isn’t controlled by a single
Information about objects is communicated to clients entity
Security and authorization are part of the protocol Information can be stored by the client to
Can be fully described using WSDL prevent multiple calls
Can return data in multiple formats (JSON, XML,
etc.)
Spends a lot of bandwidth communicating metadata Only works on top of the HTTP protocol
Cons Hard to implement and is unpopular among web and mobile Hard to enforce authorization and security on
developers top of it
When clients need to have access to objects available on When clients and servers operate on a web
When to servers environment
use When you want to enforce a formal contract between a client When information about objects doesn’t need to
and a server be communicated to the client
When you need to enforce a strict contract
When you want the majority of developers to easily use your
When not between a client and a server
API
to use When performing transactions that involve
When your bandwidth is very limited
multiple calls
Social media services
Financial services
Social networks
Use cases Payment gateways
Web chat services
Telecommunication services
Mobile services
www.salesforce.com/developer/docs/api/—
Examples https://dev.twitter.com/
Salesforce SOAP API
Use SOAP if you are dealing with transactional operations Use REST if you’re focused on wide-scale API
Conclusion and you already have an audience that is satisfied with this adoption or if your API is targeted at mobile
technology apps

Web Architectural Style


According to Fielding, there are two ways to define a system:
One is to start from a blank slate—an empty whiteboard—with no initial knowledge of the
system being built or the use of familiar components until the needs are satisfied.
A second approach is to start with the full set of needs for the system, and constraints are
added to individual components until the forces that influence the system are able to
interact in harmony with each other.
REST follows the second approach. In order to define a REST architecture, a null state is
initially defined—a system that has no constraints whatsoever and where component
differentiation is nothing but a myth—and constraints are added one by one. The following
subsections cover web architectural style constraints. Each of these constraints defines how
the framework for RESTful APIs should be architected and designed. Security is another
aspect which needs to be considered independently as part of this framework when rolling
out RESTful APIs to the end users.

Client-Server
Visit https://ebookmass.com today to explore
a vast collection of ebooks across various
genres, available in popular formats like
PDF, EPUB, and MOBI, fully compatible with
all devices. Enjoy a seamless reading
experience and effortlessly download high-
quality materials in just a few simple steps.
Plus, don’t miss out on exciting offers that
let you access a wealth of knowledge at the
best prices!
Other documents randomly have
different content
back
back
back
back
back
back
back
back
back
back
back
back
back
back
back
back
back
back
back
back
back
back
back
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.

Let us accompany you on the journey of exploring knowledge and


personal growth!

ebookmass.com

You might also like