What is an API Fragment?

api fragments

An API fragment is a portion of an API specification, which is why understanding it starts at the API specification level. An API spec consists of a plan of how your API should look structurally – like a blueprint of a house.

The API spec documents what an API does and the expected call and response you can expect from it. It’s a key part of API development because it can help you isolate design flaws or problems before you write a line of code. A way to create APIs more efficiently is to get reuse by reusing portions or fragments of APIs into specs.

Reusable APIs and API fragments are a critical factor in closing the IT delivery gap that arises when there are too many IT projects that need to be delivered with too few IT resources. Instead of starting every project from scratch, you can reuse fragments and APIs to accelerate project delivery.

Let’s imagine you were building a customer API. You’ll notice that some of the snippets or “fragments” of the API spec have a lot of potential for reuse. This can be a security scheme or a data type. For example, a customer data type can consist of first name, last name, and address.

Most likely, the way you describe a customer stays consistent across your APIs, which makes this data type, or fragment, reusable. If you build a library of these fragments, you then have many assets for reuse that can accelerate the speed of building your API spec.

Why reusable APIs and API fragments are so important

Just as it’s important to have reusable APIs available to overcome the constant demand for time-consuming custom point-to-point integrations, it’s equally important to have reusable API fragments to make the design and build of a reusable API even quicker and easier. Then, as you’re building an API, you can save the fragments into a central repository be discovered and used by your colleagues in your organization.

An example of how this might work is the omnichannel API created by the MuleSoft team for the Catalyst Accelerator for Retail, which kickstarts retailers’ digital transformation. This omnichannel API provides methods to support a mobile/web store like product search, shopping cart, customer profiles, etc.

From this one API, our team created 24 fragments of the API spec, including a Customer fragment, an Address fragment, a MapURL fragment, a Shopping Cart fragment…the list goes on and on. Those fragments can be reused in other API specs to create different APIs that serve a different purpose.

Another advantage of building an API spec out of reusable API fragments is that consistency of definitions reduces the effort of implementing APIs. Since “Address” is defined the same way across all APIs, you don’t have to transform that particular function when it’s reused in various services. If you expand that efficiency across all fragments and specs, you eliminate a ton of transformation work, and you, therefore, reduce the time to deliver.

Anypoint Platform Crowd release helps you take advantage of reusable API fragments

In the latest release of Anypoint Platform, called Crowd, users will be able to truly take advantage of API fragments. Crowd delivers the capabilities that make efficient API reuse and consumption not only possible, but easy. A key component in the release is Anypoint Exchange; it helps users facilitate the reuse component of Anypoint Platform. As users start defining API fragments, they can be published to Exchange and then made available for discovery across the organization at the point of design. Once using the assets, users can also rate it or leave comments and questions.

Another key component in the release is Anypoint Design Center – API designer. This is where the API fragment and spec design takes place. API designer is fully integrated with the Anypoint Exchange, which means that you can save and reuse fragments and API specs all within the API designer interface.

The tight integration of API designer and Anypoint Exchange is really critical to creating the efficient workflow necessary to close the IT delivery gap. Without the connection between API designer and Exchange you would probably have to search multiple repositories (like Sharepoint, Confluence, etc.) to find the API fragments you need.

After searching all over the place for your necessary components, you might very well just give up and create yet another version of “Address” that wouldn’t look anything like what your predecessors created, wasting both time and effort for you and making life difficult for future developers. The consistency and visibility the tooling provides make reuse possible, increasing productivity and efficiency.

Give the Crowd release a try

Taking advantage of reusable API fragments is a really exciting part of the Crowd release, but it’s not the only cool part of the release. It also includes an easy-to-access web-based flow designer for integration. Give the latest release a try and see what you think! Also, to help you get started with Crowd, and learn more about its new features, we’re hosting a webinar and demo to show you how to get started and accomplish use cases with it. Watch it now!


 


We'd love to hear your opinion on this post