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
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

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
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

Because the DevOps movement has redefined engineering responsibilities, SREs now have to become stewards of observability strategy.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Related

  • Generic and Dynamic API: MuleSoft
  • Releasing MuleSoft API
  • API-Led Example: MuleSoft
  • On-Demand-Schedulers With MuleSoft CloudHub APIs

Trending

  • How to Merge HTML Documents in Java
  • How Kubernetes Cluster Sizing Affects Performance and Cost Efficiency in Cloud Deployments
  • Designing for Sustainability: The Rise of Green Software
  • Assessing Bias in AI Chatbot Responses
  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.

By 
Rakesh Kumar Jha user avatar
Rakesh Kumar Jha
·
Nov. 02, 17 · Tutorial
Likes (5)
Comment
Save
Tweet
Share
30.7K 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.

Related

  • Generic and Dynamic API: MuleSoft
  • Releasing MuleSoft API
  • API-Led Example: MuleSoft
  • On-Demand-Schedulers With MuleSoft CloudHub APIs

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

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

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!