APIs with Bounded Contexts
Better design with domain-driven APIs
José Haro Peralta
Consultant, author, and instructor
Founder of microapis.io
Platform Summit
Oct 16-18, 2023
$ whoami
• I’m Jose
• Consultant, author, instructor
• Author of Microservice APIs
• Founder of microapis.io
• Creator of fencer
@JoseHaroPeralta
@microapis
Relio
https://getrelio.com/
Connect with me!
 Twitter: @JoseHaroPeralta
 GitHub: @abunuwas
 Newsletter: https://microapis.substack.com
 LinkedIn: https://www.linkedin.com/in/jose-haro-peralta/
Agenda
 Why is API design difficult?
 How DDD helps us design better APIs
 How do we model flows?
SmartBear’s State of Software Quality | API 2023
API-First
API design is difficult
Raw materials:
 URLs
 HTTP methods
 Status codes
 Schemas
 HTTP headers
APIs are contracts with the external world
Inside-out
API design
Inside-out API design
List a historical log of user consent events
Returns information about the status of an Item.
List a user’s connected applications
Outside-in API design
What is DDD?
 Align software with business
 Incorporate the language of the business
 Create a Ubiquitous Language
 Under the processes and flows of the business
 Facilitate conversations between software and business
Domains, subdomains, and bounded contexts
 Domain represents the core area of the business
 Subdomain represents a specific area of the business
 A bounded context is a space within which the vocabulary
acquires specific meaning
Sources:
• https://www.amdocs.com/insights/blog/event-storming
• https://developer.ibm.com/tutorials/reactive-in-practice-1/
How do we model operations in APIs?
1. Customer searches the catalogue
2. Customer adds items to the cart.
3. Customer proceeds to check out.
4. After applying coupons, the system calculates the price.
5. Customer selects a payment method and enters payment details.
6. System processes payment.
7. System confirms the order.
We identify user flows and domains in the API
Heuristics for modeling operations
 How do we model payment?
 Paying is an operation, not an object or resource
 Semantics of a POST => create a resource or send data for
processing
 POST will process the payment and create a payment object
in our server
 Return the outcome of this operation to the user
 Using this heuristic, we can model nearly every business
operation through the API.
Heuristics are a
means to an end
CRUD heuristic
 Create
 Read
 Update
 Delete
CRUD vs CRUDE
APIs
Cross-domain user flows
How do we model flows in APIs?
How do we represent the relationship between endpoints to
document the flow?
 HATEOAS
 OpenAPI links
 Workflows
Documenting flows with HATEOAS
Documenting flows with OpenAPI links
Documenting flows with workflows
https://github.com/OAI/sig-workflows
Further reading
 I wrote some thoughts on bringing DDD and API design together in “APIs with
Bounded Contexts”.
 An insightful and pioneering overview of how domain-driven design can help
and empower the API design process is James Higginbotham’s Principles of
Web API Design. Another great resource that encourages a DDD approach to
API design is Patterns for API Design, by Olaf Zimmerman, Mirko Stocker,
Daniel Lübke, Uwe Zdun, and Cesare Pautasso.
 For a comprehensive overview of API design, check out Arnaud Lauret’s The
Design of Web APIs. David Biesack’s newsletter API Design Matters is also a
rich source of ideas and information about good API design.
 For more about API design heuristics for REST/OpenAPI, check out Josh
Ponelat and Lukas Rosenstock’s Designing APIs with Swagger and
OpenAPI. Check out Lukas’s talk “From Domain Model to API” for more
examples of heuristics.
 For ideas on modelling complex concepts like trust and liability, check out
Martin Verraes and Rebecca Wirfs-Brock’s article “Models and Metaphors”.
Thanks for listening!
Twitter: @JoseHaroPeralta
GitHub: @abunuwas
Newsletter: https://microapis.substack.com
LinkedIn: https://www.linkedin.com/in/jose-haro-peralta/

APIs with Bounded Contexts: Modeling APIs with Domain-Driven Design

  • 1.
    APIs with BoundedContexts Better design with domain-driven APIs José Haro Peralta Consultant, author, and instructor Founder of microapis.io Platform Summit Oct 16-18, 2023
  • 2.
    $ whoami • I’mJose • Consultant, author, instructor • Author of Microservice APIs • Founder of microapis.io • Creator of fencer @JoseHaroPeralta @microapis
  • 3.
  • 4.
    Connect with me! Twitter: @JoseHaroPeralta  GitHub: @abunuwas  Newsletter: https://microapis.substack.com  LinkedIn: https://www.linkedin.com/in/jose-haro-peralta/
  • 5.
    Agenda  Why isAPI design difficult?  How DDD helps us design better APIs  How do we model flows?
  • 6.
    SmartBear’s State ofSoftware Quality | API 2023
  • 7.
  • 8.
    API design isdifficult Raw materials:  URLs  HTTP methods  Status codes  Schemas  HTTP headers
  • 9.
    APIs are contractswith the external world
  • 10.
  • 11.
  • 12.
    List a historicallog of user consent events Returns information about the status of an Item. List a user’s connected applications
  • 15.
  • 16.
    What is DDD? Align software with business  Incorporate the language of the business  Create a Ubiquitous Language  Under the processes and flows of the business  Facilitate conversations between software and business
  • 17.
    Domains, subdomains, andbounded contexts  Domain represents the core area of the business  Subdomain represents a specific area of the business  A bounded context is a space within which the vocabulary acquires specific meaning
  • 18.
  • 19.
    How do wemodel operations in APIs? 1. Customer searches the catalogue 2. Customer adds items to the cart. 3. Customer proceeds to check out. 4. After applying coupons, the system calculates the price. 5. Customer selects a payment method and enters payment details. 6. System processes payment. 7. System confirms the order.
  • 20.
    We identify userflows and domains in the API
  • 21.
    Heuristics for modelingoperations  How do we model payment?  Paying is an operation, not an object or resource  Semantics of a POST => create a resource or send data for processing  POST will process the payment and create a payment object in our server  Return the outcome of this operation to the user  Using this heuristic, we can model nearly every business operation through the API.
  • 22.
    Heuristics are a meansto an end CRUD heuristic  Create  Read  Update  Delete CRUD vs CRUDE APIs
  • 23.
  • 26.
    How do wemodel flows in APIs? How do we represent the relationship between endpoints to document the flow?  HATEOAS  OpenAPI links  Workflows
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
    Further reading  Iwrote some thoughts on bringing DDD and API design together in “APIs with Bounded Contexts”.  An insightful and pioneering overview of how domain-driven design can help and empower the API design process is James Higginbotham’s Principles of Web API Design. Another great resource that encourages a DDD approach to API design is Patterns for API Design, by Olaf Zimmerman, Mirko Stocker, Daniel Lübke, Uwe Zdun, and Cesare Pautasso.  For a comprehensive overview of API design, check out Arnaud Lauret’s The Design of Web APIs. David Biesack’s newsletter API Design Matters is also a rich source of ideas and information about good API design.  For more about API design heuristics for REST/OpenAPI, check out Josh Ponelat and Lukas Rosenstock’s Designing APIs with Swagger and OpenAPI. Check out Lukas’s talk “From Domain Model to API” for more examples of heuristics.  For ideas on modelling complex concepts like trust and liability, check out Martin Verraes and Rebecca Wirfs-Brock’s article “Models and Metaphors”.
  • 32.
    Thanks for listening! Twitter:@JoseHaroPeralta GitHub: @abunuwas Newsletter: https://microapis.substack.com LinkedIn: https://www.linkedin.com/in/jose-haro-peralta/