DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
Building Scalable Real-Time Apps with AstraDB and Vaadin
Register Now

Trending

  • Top 10 Pillars of Zero Trust Networks
  • Getting Started With the YugabyteDB Managed REST API
  • How To Use Pandas and Matplotlib To Perform EDA In Python
  • How To Approach Java, Databases, and SQL [Video]

Trending

  • Top 10 Pillars of Zero Trust Networks
  • Getting Started With the YugabyteDB Managed REST API
  • How To Use Pandas and Matplotlib To Perform EDA In Python
  • How To Approach Java, Databases, and SQL [Video]
  1. DZone
  2. Software Design and Architecture
  3. Integration
  4. Validation Against RAML Using MuleSoft APIkit Router

Validation Against RAML Using MuleSoft APIkit Router

See how APIs designed with RAML can use the MuleSoft APIkit Router component for validation of messages against the RAML definition.

Rakesh Kumar Jha user avatar by
Rakesh Kumar Jha
·
Nov. 02, 17 · Tutorial
Like (5)
Save
Tweet
Share
29.04K Views

Join the DZone community and get the full member experience.

Join For Free

As a MuleSoft Certified Architect, Designer and Developer, I recently worked on API implementations for one of our clients using MuleSoft’s CloudHub. One common feature that we use across APIs implementations is to design an API using RESTful API Modeling Language (RAML) and validate incoming and outgoing message through the APIs against the defined RAML using the MuleSoft APIkit Router component.

In this article, we will demonstrate validating incoming messages to the APIs against the defined RAML using the MuleSoft APIkit Router component, and then conclude the scenario in which the APIkit Router doesn’t throw an exception, even passing undefined RAML parameters to the API in the request.

As we know, RAML contains API specifications like Resources, HTTP Methods, Traits, Query Parameters, URI Parameters, and JSON request and response schemas. In API implementation, Mule provides APIkit Router for routing messages, serializing responses, and validating payloads, headers, query-params, and URI-params against the RAML.

Let’s get started and define a resource in the RAML as below and create a Mule project to walk through how validation works in APIkit Router.

/policy:
  displayName: search policies by criteria
  post:
    queryParameters:
        operation:
          type: string
          required: true
          enum: [searchbycriteria]
        filter:
          type: string
          required: true
          enum: [basicdetails]

The below screen demonstrates APIkit Router configuration in the Mule project for validating and routing incoming Mule messages against the defined RAML.

Image title

Now let’s deploy the Mule project and make API calls. We will run three different test scenarios to see how the AKI kit Router validates incoming request against the RAML.

Invoking With All the Required Definitions

Let’s make an API call with all the required parameters as defined in the RAML defined above. We will see the incoming message gets validated successfully by the API Kit Router against the RAML and will give a proper success response.

Image title

Invoking With a Missing Required Query Parameter

Now let’s make an API call with a missing required query parameter “filter” as defined in the above RAML. Mule API Kit Router will throw the exception with the proper message regarding missing required “Query Parameter” defined in the RAML API definition.

Image title

ERROR 2017-10-16 15:53:05,247 [[PoliciesAPI].SDHTTP_Listener_Configuration.worker.01] org.mule.exception.CatchMessagingExceptionStrategy:

********************************************************************************

Message               : Required query parameter filter not specified

The above use cases show that APIkit Router validated the incoming Mule message to the APIs against the defined RAML specification, which seems pretty useful for an API implementation.

Now let’s take a close look at step 2 of the validation, where we received an exception when we hadn’t passed the required query parameter as defined in the RAML. What will happen when we pass some extra query parameters which are not defined in the RAML definition? Yes, this looks interesting.

Invoking With Extra (undefined) Query Parameters

Let’s pass one extra query parameter, “extraParam,” which is not defined in the above RAML specification, to the API. We will see that Mule APIkit Router validation will allow the API invocation and not throw any exceptions.

Image title

The API Kit Router validates the incoming request against the API RAML definition only for the parameters defined in the RAML specification and doesn’t validate any parameters which are not defined in the RAML specification. This is important to know for API designers and developers using MuleSoft for their API development.

Let’s share our knowledge to expand our MuleSoft community.

Thank you!

MuleSoft API

Opinions expressed by DZone contributors are their own.

Trending

  • Top 10 Pillars of Zero Trust Networks
  • Getting Started With the YugabyteDB Managed REST API
  • How To Use Pandas and Matplotlib To Perform EDA In Python
  • How To Approach Java, Databases, and SQL [Video]

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com

Let's be friends: