Book description
Strategies, best practices, and patterns that will help you design resilient microservices architecture and streamline your API integrations.In Microservice APIs, you’ll discover:
- Service decomposition strategies for microservices
- Documentation-driven development for APIs
- Best practices for designing REST and GraphQL APIs
- Documenting REST APIs with the OpenAPI specification (formerly Swagger)
- Documenting GraphQL APIs using the Schema Definition Language
- Building microservices APIs with Flask, FastAPI, Ariadne, and other frameworks
- Service implementation patterns for loosely coupled services
- Property-based testing to validate your APIs, and using automated API testing frameworks like schemathesis and Dredd
- Adding authentication and authorization to your microservice APIs using OAuth and OpenID Connect (OIDC)
- Deploying and operating microservices in AWS with Docker and Kubernetes
Microservice APIs teaches you practical techniques for designing robust microservices with APIs that are easy to understand, consume, and maintain. You’ll benefit from author José Haro Peralta’s years of experience experimenting with microservices architecture, dodging pitfalls and learning from mistakes he’s made. Inside you’ll find strategies for delivering successful API integrations, implementing services with clear boundaries, managing cloud deployments, and handling microservices security. Written in a framework-agnostic manner, its universal principles can easily be applied to your favorite stack and toolset.
About the Technology
Clean, clear APIs are essential to the success of microservice applications. Well-designed APIs enable reliable integrations between services and help simplify maintenance, scaling, and redesigns. This book teaches you the patterns, protocols, and strategies you need to design, build, and deploy effective REST and GraphQL microservices APIs.
About the Book
Microservice APIs gathers proven techniques for creating and building easy-to-consume APIs for microservices applications. Rich with proven advice and Python-based examples, this practical book focuses on implementation over philosophy. You’ll learn how to build robust microservice APIs, test and protect them, and deploy them to the cloud following principles and patterns that work in any language.
What's Inside
- Service decomposition strategies for microservices
- Best practices for designing and building REST and GraphQL APIs
- Service implementation patterns for loosely coupled components
- API authorization with OAuth and OIDC
- Deployments with AWS and Kubernetes
About the Reader
For developers familiar with the basics of web development. Examples are in Python.
About the Author
José Haro Peralta is a consultant, author, and instructor. He’s also the founder of microapis.io.
Quotes
An insightful guide for creating REST and GraphQL APIs, with neat examples using FastAPI and Flask. The service implementation patterns chapter is a must-read for every developer.
- William Jamir Silva, Adjust
A perfect introduction to microservice web APIs in Python.
- Stuart Woodward, CEO, Hanamaru
A well-designed API makes all the difference in the success of your next project. This book equips you with the knowledge and the skills you need. Excellent!
- Alain Lompo, ISO-Gruppe
Excellent coverage with practical examples.
- Sambasiva Andaluri, IBM
Table of contents
- inside front cover
- Microservice APIs
- Copyright
- dedication
- contents
- front matter
- Part 1. Introducing Microservice APIs
- 1 What are microservice APIs?
-
2 A basic API implementation
- 2.1 Introducing the orders API specification
- 2.2 High-level architecture of the orders application
- 2.3 Implementing the API endpoints
- 2.4 Implementing data validation models with pydantic
- 2.5 Validating request payloads with pydantic
- 2.6 Marshalling and validating response payloads with pydantic
- 2.7 Adding an in-memory list of orders to the API
- Summary
- 3 Designing microservices
- Part 2. Designing and building REST APIs
-
4 Principles of REST API design
- 4.1 What is REST?
-
4.2 Architectural constraints of REST applications
- 4.2.1 Separation of concerns: The client-server architecture principle
- 4.2.2 Make it scalable: The statelessness principle
- 4.2.3 Optimize for performance: The cacheability principle
- 4.2.4 Make it simple for the client: The layered system principle
- 4.2.5 Extendable interfaces: The code-on-demand principle
- 4.2.6 Keep it consistent: The uniform interface principle
- 4.3 Hypermedia as the engine of application state
- 4.4 Analyzing the maturity of an API with the Richardson maturity model
- 4.5 Structured resource URLs with HTTP methods
- 4.6 Using HTTP status codes to create expressive HTTP responses
- 4.7 Designing API payloads
- 4.8 Designing URL query parameters
- Summary
-
5 Documenting REST APIs with OpenAPI
- 5.1 Using JSON Schema to model data
- 5.2 Anatomy of an OpenAPI specification
- 5.3 Documenting the API endpoints
- 5.4 Documenting URL query parameters
- 5.5 Documenting request payloads
- 5.6 Refactoring schema definitions to avoid repetition
- 5.7 Documenting API responses
- 5.8 Creating generic responses
- 5.9 Defining the authentication scheme of the API
- Summary
-
6 Building REST APIs with Python
- 6.1 Overview of the orders API
- 6.2 URL query parameters for the orders API
- 6.3 Validating payloads with unknown fields
- 6.4 Overriding FastAPI’s dynamically generated specification
- 6.5 Overview of the kitchen API
- 6.6 Introducing flask-smorest
- 6.7 Initializing the web application for the API
- 6.8 Implementing the API endpoints
- 6.9 Implementing payload validation models with marshmallow
- 6.10 Validating URL query parameters
- 6.11 Validating data before serializing the response
- 6.12 Implementing an in-memory list of schedules
- 6.13 Overriding flask-smorest’s dynamically generated API specification
- Summary
-
7 Service implementation patterns for microservices
- 7.1 Hexagonal architectures for microservices
- 7.2 Setting up the environment and the project structure
- 7.3 Implementing the database models
- 7.4 Implementing the repository pattern for data access
- 7.5 Implementing the business layer
- 7.6 Implementing the unit of work pattern
- 7.7 Integrating the API layer and the service layer
- Summary
- Part 3. Designing and building GraphQL APIs
-
8 Designing GraphQL APIs
- 8.1 Introducing GraphQL
- 8.2 Introducing the products API
- 8.3 Introducing GraphQL’s type system
- 8.4 Representing collections of items with lists
- 8.5 Think graphs: Building meaningful connections between object types
- 8.6 Combining different types through unions and interfaces
- 8.7 Constraining property values with enumerations
- 8.8 Defining queries to serve data from the API
- 8.9 Altering the state of the server with mutations
- Summary
-
9 Consuming GraphQL APIs
- 9.1 Running a GraphQL mock server
- 9.2 Introducing GraphQL queries
- 9.3 Using fragments in queries
- 9.4 Running queries with input parameters
- 9.5 Navigating the API graph
- 9.6 Running multiple queries and query aliasing
- 9.7 Running GraphQL mutations
- 9.8 Running parameterized queries and mutations
- 9.9 Demystifying GraphQL queries
- 9.10 Calling a GraphQL API with Python code
- Summary
-
10 Building GraphQL APIs with Python
- 10.1 Analyzing the API requirements
- 10.2 Introducing the tech stack
- 10.3 Introducing Ariadne
-
10.4 Implementing the products API
- 10.4.1 Laying out the project structure
- 10.4.2 Creating an entry point for the GraphQL server
- 10.4.3 Implementing query resolvers
- 10.4.4 Implementing type resolvers
- 10.4.5 Handling query parameters
- 10.4.6 Implementing mutation resolvers
- 10.4.7 Building resolvers for custom scalar types
- 10.4.8 Implementing field resolvers
- Summary
- Part 4. Securing, testing, and deploying microservice APIs
- 11 API authorization and authentication
- 12 Testing and validating APIs
- 13 Dockerizing microservice APIs
-
14 Deploying microservice APIs with Kubernetes
- 14.1 Setting up the environment for this chapter
- 14.2 How Kubernetes works: The “CliffsNotes” version
- 14.3 Creating a Kubernetes cluster with EKS
- 14.4 Using IAM roles for Kubernetes service accounts
- 14.5 Deploying a Kubernetes load balancer
- 14.6 Deploying microservices to the Kubernetes cluster
- 14.7 Setting up a serverless database with AWS Aurora
- 14.8 Updating the OpenAPI specification with the ALB’s hostname
- 14.9 Deleting the Kubernetes cluster
- Summary
- Appendix A. Types of web APIs and protocols
- Appendix B. Managing an API’s life cycle
- Appendix C. API authorization using an identity provider
- index
- inside back cover
Product information
- Title: Microservice APIs
- Author(s):
- Release date: February 2023
- Publisher(s): Manning Publications
- ISBN: 9781617298417
You might also like
book
API Design Patterns
A collection of best practices and design standards for web and internal APIs. In API Design …
book
GraphQL in Action
Reduce bandwidth demands on your APIs by getting only the results you need—all in a single …
book
Hands-On RESTful API Design Patterns and Best Practices
Build effective RESTful APIs for enterprise with design patterns and REST framework's out-of-the-box capabilities Key Features …
book
Principles of Web API Design: Delivering Value with APIs and Microservices
The Full-Lifecycle Guide to API Design brings together principles and processes to help you succeed across …