Table Of ContentMastering
Azure API
Management
A Practical Approach to Designing and
Implementing an API-Centric
Enterprise Architecture
—
Sven Malvik
Mastering Azure
API Management
A Practical Approach to Designing
and Implementing an API-Centric
Enterprise Architecture
Sven Malvik
Mastering Azure API Management: A Practical Approach to Designing and
Implementing an API-Centric Enterprise Architecture
Sven Malvik
Fjerdingby, Norway
ISBN-13 (pbk): 978-1-4842-8010-2 ISBN-13 (electronic): 978-1-4842-8011-9
https://doi.org/10.1007/978-1-4842-8011-9
Copyright © 2022 by Sven Malvik
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: Joan Murray
Development Editor: Laura Berendson
Coordinating Editor: Jill Balzano
Cover image designed by Freepik (www.freepik.com)
Distributed to the book trade worldwide by Springer Science+Business Media LLC, 1 New York Plaza, Suite
4600, New York, NY 10004. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail orders-ny@springer-sbm.
com, 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.
Printed on acid-free paper
Hi boys, Even and Emil.
Table of Contents
About the Author ���������������������������������������������������������������������������������������������������xiii
About the Technical Reviewer ���������������������������������������������������������������������������������xv
Acknowledgments �������������������������������������������������������������������������������������������������xvii
Foreword ����������������������������������������������������������������������������������������������������������������xix
Introduction ������������������������������������������������������������������������������������������������������������xxi
Part I: Getting Started �������������������������������������������������������������������������������������1
Chapter 1: Quick Start ����������������������������������������������������������������������������������������������3
Create an Azure Account ���������������������������������������������������������������������������������������������������������������3
Provision Azure API Management �������������������������������������������������������������������������������������������������4
Add API ������������������������������������������������������������������������������������������������������������������������������������������7
Test API �����������������������������������������������������������������������������������������������������������������������������������������9
API Management Portal �����������������������������������������������������������������������������������������������������������9
Command Line �����������������������������������������������������������������������������������������������������������������������11
Summary�������������������������������������������������������������������������������������������������������������������������������������11
Chapter 2: Overview �����������������������������������������������������������������������������������������������13
Unlocking Digital Assets with APIs ����������������������������������������������������������������������������������������������13
Payments �������������������������������������������������������������������������������������������������������������������������������14
Manufacturing �����������������������������������������������������������������������������������������������������������������������14
Automotive ����������������������������������������������������������������������������������������������������������������������������15
Understanding the Basics of web APIs ���������������������������������������������������������������������������������������16
SOAP ��������������������������������������������������������������������������������������������������������������������������������������16
REST ��������������������������������������������������������������������������������������������������������������������������������������18
HTTP Clients for Testing RESTful web APIs ����������������������������������������������������������������������������21
v
Table of ConTenTs
Enterprise API Platform in Essence ���������������������������������������������������������������������������������������������22
Consistent Documentation ����������������������������������������������������������������������������������������������������23
Comprehensible Capabilities �������������������������������������������������������������������������������������������������23
Common Design Guidelines ���������������������������������������������������������������������������������������������������24
API User Onboarding ��������������������������������������������������������������������������������������������������������������24
User Management �����������������������������������������������������������������������������������������������������������������24
Health Monitoring ������������������������������������������������������������������������������������������������������������������25
Governance and Compliance �������������������������������������������������������������������������������������������������25
Versioning and Revisioning ���������������������������������������������������������������������������������������������������25
Scalability and Resiliency ������������������������������������������������������������������������������������������������������26
Security ���������������������������������������������������������������������������������������������������������������������������������26
DevOps ����������������������������������������������������������������������������������������������������������������������������������26
Performance ��������������������������������������������������������������������������������������������������������������������������27
Stability ���������������������������������������������������������������������������������������������������������������������������������27
Introducing Azure API Management ��������������������������������������������������������������������������������������������27
Azure Portal ���������������������������������������������������������������������������������������������������������������������������29
Developer Portal ��������������������������������������������������������������������������������������������������������������������31
API Gateway���������������������������������������������������������������������������������������������������������������������������32
Summary�������������������������������������������������������������������������������������������������������������������������������������33
Part II: Key Concepts ������������������������������������������������������������������������������������35
Chapter 3: APIs and Products ���������������������������������������������������������������������������������37
APIs ���������������������������������������������������������������������������������������������������������������������������������������������38
Create Blank API with Azure CLI ��������������������������������������������������������������������������������������������39
Manage APIs with Azure PowerShell �������������������������������������������������������������������������������������44
Create API from Azure Resources ������������������������������������������������������������������������������������������46
Products ��������������������������������������������������������������������������������������������������������������������������������������49
Create APIs ����������������������������������������������������������������������������������������������������������������������������50
Create Products ���������������������������������������������������������������������������������������������������������������������52
Add APIs to Products �������������������������������������������������������������������������������������������������������������53
Summary�������������������������������������������������������������������������������������������������������������������������������������54
vi
Table of ConTenTs
Chapter 4: Users and Groups ����������������������������������������������������������������������������������55
Groups �����������������������������������������������������������������������������������������������������������������������������������������56
System Groups ����������������������������������������������������������������������������������������������������������������������57
Create a Group �����������������������������������������������������������������������������������������������������������������������57
Associate Groups to Products ������������������������������������������������������������������������������������������������58
Users �������������������������������������������������������������������������������������������������������������������������������������������59
Create a User �������������������������������������������������������������������������������������������������������������������������60
Deactivate and Reactivate a User ������������������������������������������������������������������������������������������61
Add a User to a Group ������������������������������������������������������������������������������������������������������������61
Summary�������������������������������������������������������������������������������������������������������������������������������������62
Chapter 5: Versions and Revisions �������������������������������������������������������������������������63
Versions ��������������������������������������������������������������������������������������������������������������������������������������64
Version Scheme ���������������������������������������������������������������������������������������������������������������������65
Add a New Version�����������������������������������������������������������������������������������������������������������������66
Revisions �������������������������������������������������������������������������������������������������������������������������������������67
Add a New Revision ���������������������������������������������������������������������������������������������������������������68
Make Revision Current ����������������������������������������������������������������������������������������������������������69
Summary�������������������������������������������������������������������������������������������������������������������������������������69
Chapter 6: Subscriptions ����������������������������������������������������������������������������������������71
Creating a Subscription ���������������������������������������������������������������������������������������������������������������73
Revealing Subscription Keys �������������������������������������������������������������������������������������������������������74
Calling API with Subscription Key �����������������������������������������������������������������������������������������������75
Summary�������������������������������������������������������������������������������������������������������������������������������������76
Chapter 7: Policies and Named Values �������������������������������������������������������������������77
Policies ����������������������������������������������������������������������������������������������������������������������������������������78
Simple Policy �������������������������������������������������������������������������������������������������������������������������79
Scoping ����������������������������������������������������������������������������������������������������������������������������������82
Calculating Effective Policy ���������������������������������������������������������������������������������������������������85
Expressions ���������������������������������������������������������������������������������������������������������������������������86
vii
Table of ConTenTs
Named Values �����������������������������������������������������������������������������������������������������������������������������90
Plaintext ���������������������������������������������������������������������������������������������������������������������������������90
Secrets ����������������������������������������������������������������������������������������������������������������������������������93
Secrets from Azure Key Vault ������������������������������������������������������������������������������������������������94
Examples�������������������������������������������������������������������������������������������������������������������������������������99
Validations �����������������������������������������������������������������������������������������������������������������������������99
Canary Backend APIs �����������������������������������������������������������������������������������������������������������103
Summary�����������������������������������������������������������������������������������������������������������������������������������105
Chapter 8: Developer Portal ����������������������������������������������������������������������������������107
Overview �����������������������������������������������������������������������������������������������������������������������������������107
Customization ���������������������������������������������������������������������������������������������������������������������������113
Styling ���������������������������������������������������������������������������������������������������������������������������������114
Notifications and Templates ������������������������������������������������������������������������������������������������115
Self-hosting ������������������������������������������������������������������������������������������������������������������������������117
Running the Developer Portal Locally ����������������������������������������������������������������������������������117
Summary�����������������������������������������������������������������������������������������������������������������������������������120
Part III: Workflow ����������������������������������������������������������������������������������������121
Chapter 9: API Development in Context ����������������������������������������������������������������123
Centralized API Repository ��������������������������������������������������������������������������������������������������������124
Internal Repository ��������������������������������������������������������������������������������������������������������������124
External Repository �������������������������������������������������������������������������������������������������������������125
Application Repositories �����������������������������������������������������������������������������������������������������������127
Product Deployment with Azure Pipeline ����������������������������������������������������������������������������������129
Summary�����������������������������������������������������������������������������������������������������������������������������������132
viii
Table of ConTenTs
Chapter 10: Developing Policies ���������������������������������������������������������������������������133
Azure Portal�������������������������������������������������������������������������������������������������������������������������������133
Visual Studio Code Extension ����������������������������������������������������������������������������������������������������136
Installation ���������������������������������������������������������������������������������������������������������������������������136
Developing a Policy �������������������������������������������������������������������������������������������������������������139
Testing an API ����������������������������������������������������������������������������������������������������������������������141
Debugging a Policy ��������������������������������������������������������������������������������������������������������������143
Summary�����������������������������������������������������������������������������������������������������������������������������������146
Chapter 11: Deploying APIs ����������������������������������������������������������������������������������147
ARM Templates �������������������������������������������������������������������������������������������������������������������������147
Bicep �����������������������������������������������������������������������������������������������������������������������������������������154
REST ������������������������������������������������������������������������������������������������������������������������������������������156
Terraform ����������������������������������������������������������������������������������������������������������������������������������160
Summary�����������������������������������������������������������������������������������������������������������������������������������162
Chapter 12: Power Apps ���������������������������������������������������������������������������������������165
Creating a Connection ���������������������������������������������������������������������������������������������������������������166
Creating a Power App����������������������������������������������������������������������������������������������������������������169
Summary�����������������������������������������������������������������������������������������������������������������������������������172
Part IV: Enterprise Integration ��������������������������������������������������������������������173
Chapter 13: Networking ����������������������������������������������������������������������������������������175
Internal Virtual Network (VNET) �������������������������������������������������������������������������������������������������176
External VNET ����������������������������������������������������������������������������������������������������������������������������179
No VNET ������������������������������������������������������������������������������������������������������������������������������������180
Backend Integration with AKS ���������������������������������������������������������������������������������������������������182
Summary�����������������������������������������������������������������������������������������������������������������������������������186
ix
Table of ConTenTs
Chapter 14: Self-hosted API Gateway �������������������������������������������������������������������187
Creating a Self-hosted API Gateway �����������������������������������������������������������������������������������������189
Deploying a Self-hosted API Gateway ���������������������������������������������������������������������������������������191
Configuration �����������������������������������������������������������������������������������������������������������������������191
Deployment �������������������������������������������������������������������������������������������������������������������������194
Updating the Self-hosted API Gateway �������������������������������������������������������������������������������������195
Summary�����������������������������������������������������������������������������������������������������������������������������������195
Part V: Maintenance �����������������������������������������������������������������������������������197
Chapter 15: Security ���������������������������������������������������������������������������������������������199
Authentication ���������������������������������������������������������������������������������������������������������������������������199
HTTP Basic Authentication to Backend Web Services ���������������������������������������������������������199
Authentication with OAuth 2�0 ���������������������������������������������������������������������������������������������202
Other Security Aspects ��������������������������������������������������������������������������������������������������������������214
Subscriptions �����������������������������������������������������������������������������������������������������������������������215
Protecting Against Path Traversal Attacks ���������������������������������������������������������������������������216
Summary�����������������������������������������������������������������������������������������������������������������������������������218
Chapter 16: Logging and Monitoring ��������������������������������������������������������������������219
Logging via Event Hub ��������������������������������������������������������������������������������������������������������������220
Deploy an Azure Event Hub��������������������������������������������������������������������������������������������������221
Set Event Hub Logger to Azure API Management ����������������������������������������������������������������222
Add Event Hub Logger to Policy �������������������������������������������������������������������������������������������223
Observing Logs with VS Code ����������������������������������������������������������������������������������������������224
Logging to Azure Log Analytics �������������������������������������������������������������������������������������������������226
Azure Application Insights ���������������������������������������������������������������������������������������������������������228
Summary�����������������������������������������������������������������������������������������������������������������������������������231
x