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
headers:
  transaction-id:
         type: string
         required: false
  transaction-type:
         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
properties:
  errorResponse:
    type: object
    properties:
      transactionId:
        description: TransactionId of the request that failed
        type: string
        required: false
      errorimeStamp:
        description: timestamp at which the error occurred
        type: string
        required: false
      errors:
        description: description of the error/exception
        type: array
        required: false
        items:
          type: object
          properties:
            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:
Subscribe
Notify of
guest
1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Kinnera
Kinnera
4 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.