Join us to learn about Basic of RAML and how to publish API to exchange in MuleSoft. We will learn about resourceTypes, Using ! include, types and type in RAML.
When & How to use resourcesTypes?
- “resourceTypes” refers to a way to define reusable templates or blueprints for different types of resources in your API.
- Think of them like a set of instructions that you can use to create consistent and standardised resource definitions.
- Used for Best practices to avoid writing code again and again.
- The resourceTypes uses some user-defined parameters surrounded by double angle brackets (<< and >>)
- <resourcePath> – represents the entire URI (not URL)
- <resourcePathName> – represents the part of URI (the oath of the URI following the right most forward slash)
- Parameter functions for example:
!singularize
!pluralize
!uppercase
!lowercase
!uppercamelcase
!lowercamelcase
!upperunderscorecase
!lowerunderscorecase
!upperhyphencase
!lowerhyphencase - For example, given the resource /health, where <> evaluates to “health”
<resourcePathName | !uppercase> ==> “HEALTH”
HANDS-ON
When & How to use traits?
- “traits” are a kind of resourceTypes
- Understand this way : resourceTypes are used to extract pattern from “resource” definitions (resource level) , whereas , traits are used to extract patterns from “method” definitions that are common across resources.
- In simpler terms, traits are defined to use whenever there is a common functionality needs to be implemented across more than one method at-least.
Purpose?
- First, we need to identify the redundant(repeated) sections of our resources, recognize their patterns, and extract resource types.
- Then should do the same for the methods that are common across resources to extract traits. Then we will be able to eliminate further redundancies by applying traits to our resource types .
- To summarize, we use resourceTypes and traits to eliminate writing the same code repeatedly . Instead, Write once and use it across
Summary
Checkout our complete MuleSoft Training to learn all about MuleSoft. We have 15+ session for you with Final Project.
Good