Behavior extensibility

Composable Commerce allows you to extend the behavior of an API using either asynchronous or synchronous methods.

  • After completing this page, you should be able to:

    • Explain what behavior extensibility is.
    • Differentiate between the different types of behavior extensibility options that Composable Commerce offers.
  • Asynchronous vs synchronous behavior

    Composable Commerce allows you to extend the behavior of its APIs with your business logic. In other words, you can customize how an API behaves. You can extend an API behavior using synchronous or asynchronous methods.

    In synchronous behavior, the caller of the API has to wait for an answer. This often means that the end-user of your application is waiting until a certain decision or action is taken by the application. In an asynchronous system, the application is aware that some action needs to be taken, but it can execute it in a non-blocking way.

    Choosing whether to use a synchronous or asynchronous approach depends on your use case. For example, sending order confirmation emails using a synchronous system would cause your users an unnecessary wait time. This can be avoided by having an asynchronous process in place.

    A synchronous approach is suitable for when you want to intercept a process and change its outcome dependent on certain conditions. A clear example of synchronous behavior is validating the contents of a cart. Imagine you have a business requirement where a customer cannot buy more than 6 tickets to a single concert. You can set up an application that checks this requirement. This application can be triggered by Order-creation in Composable Commerce. Before an Order is saved, the application can validate the contents of the Cart and decide whether to proceed with the Order or not.

    You can customize the behavior of Composable Commerce APIs using:

    Subscriptions

    Subscriptions are used to trigger an asynchronous background process in response to an event in Composable Commerce. Common use cases include sending an order confirmation email, charging a credit card after a delivery has been made, or synchronizing customer accounts to a customer relationship management (CRM) system.

    As you can see from the sequence diagram below, Composable Commerce sends a notification after the Cart has been updated.

    API Extensions

    An API Extension gets called after the processing of a create or update request of an API call, but before the result is persisted. The API Extension can validate the object in the request, or apply additional updates to it.

    In the sequence diagram below, you can see that a response from the API Extension is required before Composable Commerce can update the Cart (reference point 6).

    Your use case will likely determine which extensibility option fits best. However, using Subscriptions over API Extensions whenever possible, will lead to better overall performance.

    Test your knowledge