[27-02-2021]
[Kochi] MuleSoft Meetup Group
RAML, Dataweave functions.
2
Introductions
● API + RAML Best Practices
● The Power of dataweave
Agenda
3
Organizers
Supriya Pawar
Technical Lead at
Accenture
About the organizer:
 Kochi MuleSoft Meetup Leader.
 7+ Years of Experience in Integrations and API Technologies.
 Certified MuleSoft Developer, Integration Architect and platform Architect.
4
Speakers
Sanjana Mishra
Senior Developer at Accenture
About the Speaker:
 Having 5+ years of overall experience building integration solutions.
 Certified MuleSoft Developer And Platform Architect.
About the Speaker:
 5+ Years of Experience in Integrations and API Technologies.
 Certified MuleSoft Developer, Integration Architect and platform
Architect.
Sumit Ahuja
Senior Developer at Accenture
RAML + API Best Practices
6
What is RAML ? Why we use it ?
Best Practices in RAML ?
● Use Spec Driven Development
● Think about the API
● Modularize and Reuse
● Mocking
● Resources and Naming
● HTTP Codes and Verbs
7
8
Use Spec Driven Development
● Use Design Patterns/ Code Reuse.
● Mock and get User Feedback.
● Make Necessary Changes.
● Start Coding to the Spec and don't deviate.
9
Benefits of Spec Driven
● Parallelize the development process
● Improves understanding of the whole
● Guide Development
10
Think about the API
11
Think of a Long term
● Your API is a Contract
● Versioning is not a Solution
● You can pay a little now , or much more Later.
● You need to think things through
● Mindset is everything
12
Think Things Through
● Who is your API for ?
● What type of API are you building ?
● How are you going to maintain your API ?
● How are you going to document your API ?
● How are you going to lets users interact with your API ?
● How are you going to manage authentication, provisioning and developer security ?
● How are going to protect your servers against attacks etc ?
● How are you going to manage support ?
13
Who Will Be Using Your API?
14
Versioning – A Necessary Evil
● Problems with versioning :
○ Backward Incompatibilities
○ Multiple services to maintain
○ Multiple systems to support
○ Creates Confusion among developers
15
Modularize and Reuse (RAML Inheritance)
● This can be Best achieved using the below two features of RAML :
○ Resource Types
■ ResourceType is basically a template that is used to define the descriptions, methods, and parameters that
can be used by multiple resources without writing the duplicate code or repeating code.
○ Traits
■ Traits is like function and is used to define common attributes for HTTP method (GET, PUT, POST,
PATCH, DELETE, etc) such as whether or not they are filterable, searchable, or pageable.
16
Defining Resource Types
17
Calling resource Types from RAML
18
Declaring Traits
19
Calling Traits from Resource Types and Resources
20
Mocking
● The API mocking service enables you simulate the behavior of an API specification. The
mocking service provides a test link to an API. The mocking service returns the responses
(both HTTP status codes and example payloads) that are defined in your API specification
and is valuable for testing or for simply exploring how your API behaves.
● Simulate a Call to an API using an Internal URL
● Simulate a Call to an API using a Public URL
21
Simulate a Call to an API using an Internal URL
22
Simulate a Call to an API using a Public URL
23
Resources and Naming
● Use of camelCase for placeholders in URL.
● Use nouns in lowercase to represent a resource, for resources with multiple words, use
lowercase for all the words or use '-' (dash) in between the words and make it readable.
● Use of Parameters:
○ URI Parameter
○ Query Parameter
24
Example
25
HTTP Codes
● 1xx : Informational
● 2xx : Success
● 3xx : Redirect
● 4xx : Client error
● 5xx : Server error
26
HTTP verbs
● GET
● PUT
● PATCH
● POST
● DELETE
27
Power of Dataweave
Overview
● DataWeave is the MuleSoft expression language for accessing and transforming data within
mule apps
● Not only limited to data transformation
● Provides module or lambda function creation support
● Supports flow control and Scope Operations
● Provides feasibility for streaming for efficient processing of large documents without
overloading memory
● Datasense or preview mapping to avoid possible errors
29
Data Formats
30
31
● Sample snippet to read a XLS file using DWL vs Java
Read Function
Logging
32
● Use this function to help with debugging DataWeave scripts
33
● Flow control operations such as If else , do , else if can be used
Flow Control and Scope Operations
Lookup Operation
● Enables you to execute a flow from within dataweave and use the payload for further
processing
● In case the flow to be executed has a external connection you can provide a timeout value.
● Note : The lookup function does not support calling subflow
34
35
● The Below example creates the lambda function to check validity by comparing dates
Creating Lambda Functions
Creating Lambda Functions (Using Variable)
36
● The Below example create executes the lambda function and stores in variable
checkValildity.
Using Map Iterator
37
● Use to iterate over array or list of values
Map Object
38
● Use to iterate over key value pairs of objects
Filter
39
● The value inside array can be also referred as $
● To filter an array as per given function
Get Set from Objects
40
41
● The accumulator can be referred as $$
● The value in the array can be referred as $
Reduce
42
● Combine set of subarrays into single array
● It flattens only the first level of subarrays and omits empty subarrays
Flatten
43
● Iterates over an object and returns an array of keys, values, or indices from the object.
● It is an alternative to mapObject which is similar but returns an object, instead of an array.
Pluck
keysOf – Mule 4.3
44
valuesOf – Mule 4.3
45
firstWith – Mule 4.3
46
47
● How to get a Object from Map operator
Quick Hacks
48
● How to dynamically populate a value
Quick Hacks
Introduce yourself to your neighbor
Networking time
Thank you

Mule soft meetup__official__feb-27_2021

  • 1.
    [27-02-2021] [Kochi] MuleSoft MeetupGroup RAML, Dataweave functions.
  • 2.
    2 Introductions ● API +RAML Best Practices ● The Power of dataweave Agenda
  • 3.
    3 Organizers Supriya Pawar Technical Leadat Accenture About the organizer:  Kochi MuleSoft Meetup Leader.  7+ Years of Experience in Integrations and API Technologies.  Certified MuleSoft Developer, Integration Architect and platform Architect.
  • 4.
    4 Speakers Sanjana Mishra Senior Developerat Accenture About the Speaker:  Having 5+ years of overall experience building integration solutions.  Certified MuleSoft Developer And Platform Architect. About the Speaker:  5+ Years of Experience in Integrations and API Technologies.  Certified MuleSoft Developer, Integration Architect and platform Architect. Sumit Ahuja Senior Developer at Accenture
  • 5.
    RAML + APIBest Practices
  • 6.
    6 What is RAML? Why we use it ?
  • 7.
    Best Practices inRAML ? ● Use Spec Driven Development ● Think about the API ● Modularize and Reuse ● Mocking ● Resources and Naming ● HTTP Codes and Verbs 7
  • 8.
  • 9.
    Use Spec DrivenDevelopment ● Use Design Patterns/ Code Reuse. ● Mock and get User Feedback. ● Make Necessary Changes. ● Start Coding to the Spec and don't deviate. 9
  • 10.
    Benefits of SpecDriven ● Parallelize the development process ● Improves understanding of the whole ● Guide Development 10
  • 11.
  • 12.
    Think of aLong term ● Your API is a Contract ● Versioning is not a Solution ● You can pay a little now , or much more Later. ● You need to think things through ● Mindset is everything 12
  • 13.
    Think Things Through ●Who is your API for ? ● What type of API are you building ? ● How are you going to maintain your API ? ● How are you going to document your API ? ● How are you going to lets users interact with your API ? ● How are you going to manage authentication, provisioning and developer security ? ● How are going to protect your servers against attacks etc ? ● How are you going to manage support ? 13
  • 14.
    Who Will BeUsing Your API? 14
  • 15.
    Versioning – ANecessary Evil ● Problems with versioning : ○ Backward Incompatibilities ○ Multiple services to maintain ○ Multiple systems to support ○ Creates Confusion among developers 15
  • 16.
    Modularize and Reuse(RAML Inheritance) ● This can be Best achieved using the below two features of RAML : ○ Resource Types ■ ResourceType is basically a template that is used to define the descriptions, methods, and parameters that can be used by multiple resources without writing the duplicate code or repeating code. ○ Traits ■ Traits is like function and is used to define common attributes for HTTP method (GET, PUT, POST, PATCH, DELETE, etc) such as whether or not they are filterable, searchable, or pageable. 16
  • 17.
  • 18.
  • 19.
  • 20.
    Calling Traits fromResource Types and Resources 20
  • 21.
    Mocking ● The APImocking service enables you simulate the behavior of an API specification. The mocking service provides a test link to an API. The mocking service returns the responses (both HTTP status codes and example payloads) that are defined in your API specification and is valuable for testing or for simply exploring how your API behaves. ● Simulate a Call to an API using an Internal URL ● Simulate a Call to an API using a Public URL 21
  • 22.
    Simulate a Callto an API using an Internal URL 22
  • 23.
    Simulate a Callto an API using a Public URL 23
  • 24.
    Resources and Naming ●Use of camelCase for placeholders in URL. ● Use nouns in lowercase to represent a resource, for resources with multiple words, use lowercase for all the words or use '-' (dash) in between the words and make it readable. ● Use of Parameters: ○ URI Parameter ○ Query Parameter 24
  • 25.
  • 26.
    HTTP Codes ● 1xx: Informational ● 2xx : Success ● 3xx : Redirect ● 4xx : Client error ● 5xx : Server error 26
  • 27.
    HTTP verbs ● GET ●PUT ● PATCH ● POST ● DELETE 27
  • 28.
  • 29.
    Overview ● DataWeave isthe MuleSoft expression language for accessing and transforming data within mule apps ● Not only limited to data transformation ● Provides module or lambda function creation support ● Supports flow control and Scope Operations ● Provides feasibility for streaming for efficient processing of large documents without overloading memory ● Datasense or preview mapping to avoid possible errors 29
  • 30.
  • 31.
    31 ● Sample snippetto read a XLS file using DWL vs Java Read Function
  • 32.
    Logging 32 ● Use thisfunction to help with debugging DataWeave scripts
  • 33.
    33 ● Flow controloperations such as If else , do , else if can be used Flow Control and Scope Operations
  • 34.
    Lookup Operation ● Enablesyou to execute a flow from within dataweave and use the payload for further processing ● In case the flow to be executed has a external connection you can provide a timeout value. ● Note : The lookup function does not support calling subflow 34
  • 35.
    35 ● The Belowexample creates the lambda function to check validity by comparing dates Creating Lambda Functions
  • 36.
    Creating Lambda Functions(Using Variable) 36 ● The Below example create executes the lambda function and stores in variable checkValildity.
  • 37.
    Using Map Iterator 37 ●Use to iterate over array or list of values
  • 38.
    Map Object 38 ● Useto iterate over key value pairs of objects
  • 39.
    Filter 39 ● The valueinside array can be also referred as $ ● To filter an array as per given function
  • 40.
    Get Set fromObjects 40
  • 41.
    41 ● The accumulatorcan be referred as $$ ● The value in the array can be referred as $ Reduce
  • 42.
    42 ● Combine setof subarrays into single array ● It flattens only the first level of subarrays and omits empty subarrays Flatten
  • 43.
    43 ● Iterates overan object and returns an array of keys, values, or indices from the object. ● It is an alternative to mapObject which is similar but returns an object, instead of an array. Pluck
  • 44.
  • 45.
  • 46.
  • 47.
    47 ● How toget a Object from Map operator Quick Hacks
  • 48.
    48 ● How todynamically populate a value Quick Hacks
  • 49.
    Introduce yourself toyour neighbor Networking time
  • 50.