Create Fragments In RAML 1.0


In this tutorial we will demonstrate how can we Create Fragments In RAML 1.0

API fragments are reusable component of RAML to make the design and build of a reusable API even quicker and easier.

Another advantage of building an API spec out of reusable API fragments is that consistency of definitions reduces the effort of implementing APIs.

In this tutorial I will demonstrate how to create the RAML fragments

Login in to Anypoint platform -> Go to design Center

Click on Create new-> Create fragment

Create Fragments In RAML


Provide the fragment name

Create Fragments In RAML


We can create separate folders to create the different fragments like DataType/Traits/Example etc.

Create commonHeaders Trait as Fragment

Create Fragments In RAML


#%RAML 1.0 Trait
displayName: Header Trait
         type: string
         required: false
         type: string
         required: false


Create genericError Data Type as fragment


Add the details

Create Fragments In RAML


#%RAML 1.0 DataType
displayName:  Generic Error Type
description:  Common error fields for across apis
    type: object
        description: TransactionId of the request that failed
        type: string
        required: false
        description: timestamp at which the error occurred
        type: string
        required: false
        description: description of the error/exception
        type: array
        required: false
          type: object
            errorCode: string
            errorMessage: string


Create basicAuth Security Scheme as Fragment Type


Add the details


#%RAML 1.0 SecurityScheme
type: Basic Authentication
displayName: BasicAuth
description: This security scheme validates requests to the API using client ID and client Secret as basic auth


Publish the created fragments on Exchange so that it can be reusable across all the API’s across organization

Click publish button on top right corner

Provide the asset version


Fragments published to exchange can be reused in RAML, I will demonstrate how can we reuse fragments in RAML in next tutorial


Thank you for taking out time to read the above post. Hope you found it useful. In case of any questions, feel free to comment below. Also, if you are keen on knowing about a specific topic, happy to explore your recommendations as well.
For any latest updates or posts on our website, you can follow us on LinkedIn. Look forward to connecting with you there.

Share this:
Notify of
1 Comment
Newest Most Voted
Inline Feedbacks
View all comments
2 years ago

The articles are great. I would love to see more about on premise installation. And more explanation about how to setup vpn and dlb and all.