Tutorial 0: A Beginner's Guide to MAP

This tutorial is the "Hello World" of API design with MAP. It introduces you to the website organization and a single pattern, Pagination.

Tutorials Overview Self Study 0

Time estimate: You should be able to complete this basic tutorial in about 20-25 minutes.

Let us begin to explore the MAP language in three steps:

  1. Understand the sample API requirements
  2. Explore MAP website and language
  3. Select and apply a pattern to improve the API

Step 0: Understand the Sample API Requirements

Baseline: Let’s assume that the following customer search API has been implemented and released:

API description MAPTutorial0Sample

data type Customer {"name": D<string>, "address": D<string>, "bday": D<string>}

endpoint type CustomerLookup 
exposes 
  operation findCustomer 
    expecting payload "searchFilter": D<string> 
    delivering payload "customerList": Customer*

The search filter is a simple string value D<string>. The response message of the findCustomer operation in the API description can return many results Customer*; each of these results describes all data that has been collected about a particular customer. Hence, preparing the response data on the API provider side (and processing it on the client side) takes rather long.

Goal: Our task is to improve the above API description to support an incremental query processing. In other words, the search results should be returned in multiple manageable chunks (or slices).

Step 1: Explore Website and Pattern Language

Designing Web APIs is a complex undertaking. Hence, the API Patterns website and language might be a bit overwhelming at first glance.1 To be able to select a pattern that helps us meet the goal established in Step 0, we first have to get an overview and orient ourselves. There are several ways to do that.

Task 1.1: Home page and cheat sheet

Have a look at the home page of the MAP website:

  1. Which API design questions are raised?
  2. Which microservice pattern categories are available (hint: there are five)?
Solution (click to show)
  1. The motivating questions are:
    • “How many services should be exposed? What is an adequate size for them?”
    • “How to ensure that services are loosely coupled? How much data do they exchange, and how often does this happen?”
    • “What are the most suitable message representations? How to agree on the meaning of each message?”
  2. Three categories that contain full pattern texts are evolution, quality, and structure. The responsibility and the foundation categories arrived in 2020 and 2021.

Next, browse the the cheat sheet presenting some API design heuristics:

  1. Which API design topics does the cheat sheet cover?
  2. Does any of the issues-to-patterns tables mention “performance problems” (that occur according to our baseline from Step 0)?
Solution (click to show)
  1. The topics follow a common Web API design and evolution life cycle: Getting Started with API Design, API Release and Productization Continuous API Improvement, API Support and Maintenance.
  2. In section “Improving Runtime Behavior”, there is an entry “My clients report performance problems”.

Task 1.2: Pattern categories and filters

Have a look at the pattern categories page:

  • Do any of these categories cover the content of request and response messages (remember: we are supposed to redesign at least one such message)?
  • How about API quality tradeoffs?

Solution (click to show)

The Structure category covers the number and structure (i.e., nesting) of the representation elements in request and response messages. The Quality category description mentions quality (attribute/property) tradeoffs.

Optional tasks

Also try out the following website and language navigation options:

  1. Go to Pattern Filters. Which scopes and phases are defined? Which phase classification is used?
  2. Move on to Patterns by Quality. Is performance featured? Which patterns can help improve it?
  3. Finally, quickly also review the alphabetical Pattern Index. Are there any additional patterns worth exploring at this point?

Solution(s) (click to show)

The answers to the orientation questions can be found on the three pages you were asked to visit:

  1. For instance, two scopes are “API endpoint” and “operation”; phases are “inception (sprint 0)”, “elaboration (spikes)”, and “construction (development iterations)”.
  2. Performance is listed as a force, and patterns such as Rate Limit are referenced.
  3. How about having a look at the Wish List?

Step 2: Select and Apply a Pattern to Improve the API

Task 2.1: Review Pagination Pattern

Now read the problem statement and the solution summary and sketch of the Pagination pattern (note that our API patterns book has a much more detailed solution description including variants). Optionally, also read its context, forces, and consequences sections (note: you can use the links to the section at the top of the pattern page to navigate within the pattern):

  1. Does the pattern address/solve the problem stated in the baseline (Step 0)?
  2. Which variants exist (hint: consult Chapter 7 of our book or the EuroPLoP 2017 paper version of the pattern?

Solution(s) (click to show)

  1. Yes it does address this problem: the problem statement mentions large amounts of data, and the solution recommends dividing the response into chunks.
  2. The pattern variants are Offset-Based Pagination, Cursor-Based Pagination (also known as Token-Based Pagination) and Time-Based Pagination.

Task 2.2: Apply Pagination to sample contract

Improve the API contract to apply one of the Pagination variants as described under “How it Works” on the patterns page.

Solution (click to show)

Offset/page and cursor-based pagination can be modeled with additional data types, used in the response messages to realize the desired slicing and support navigation within the result set2 (notation: MDSL):

API description MAPTutorial0Sample

data type Customer {
  "name": D<string>, 
  "address": D<string>, 
  "birthday": D<string>}
data type CustomerPage {
  "pageContent": Customer*,
  "navigation": PageCursor, 
  "statistics": PageMetadata?}
data type PageCursor {
  "thisPage": PageID, 
  "previousPage": PageID, 
  "nextPage": PageID}
data type PageMetadata {
  "totalResultCount": MD<int>, 
  "pageSize": MD<int>, 
  "offsetNumber": PageID}
data type PageID L<string>

endpoint type CustomerLookup 
exposes 
  operation findCustomer with responsibility RETRIEVAL_OPERATION
    expecting payload "searchFilter": D<string> 
    delivering payload "customerList": Customer*

  operation findCustomerPaginated with responsibility RETRIEVAL_OPERATION
    expecting payload "searchFilter": D<string> // could specify page size here  
    delivering payload "customerPage": CustomerPage    

Note that MD stands for Metadata Element or, in short, metadata. L represents a Link Element (such as a URI). It is also possible to write Metadata<int> and Link<int>.

End Result

Having completed the above step(s), you should have gained an overview of MAP language and Website, familiarized yourself with structure and content of the Pagination pattern and created a single artifact:

  • Enhanced API description (service contract).

Note: A more complete example of pagination can be found in the Lakeside Mutual (LM) sample implementation that is available in a public GitHub repository.

Next: Self-Paced Exercise and Repetition Questions

You can find a self-paced tutorial and repetition questions with the same basic scope here. And an introductory article can be found here.

Feedback appreciated! Contact us.


  1. API design has many facets, which makes it hard to group the patterns cohesively. We envy Enterprise Integration Patterns a bit: as a language for asynchronous, queue-based messaging, it is elegantly organized to follow the message lifecycle from construction to routing and transformation to consumption.↩︎

  2. In case you are wondering which service contract notation is used in this tutorial, have a look here.↩︎