Categories: Mule 4MulesoftRAML

How to Use APIkit Router in Mule 4

Introduction

The APIkit Router element allows you to define an API. It helps developers generate whole code from the API specification (RAML file) itself. But apart from generating flows from the API specification, it also helps in routing the incoming requests to specific flows of the API.

The APIkit router is a key message processor that validates requests against the RAML definition, enriches messages, for example by adding default values to the messages, and routes requests to a flow. “Bad request” is returned if the request is invalid, for example, and “Not implemented” is returned if the RAML resource that you request is not associated with a flow.

Steps to Use APIkit Router

1. Create an API specification (RAML). You can create an API specification from the Design Center(Anypoint Platform) or you can create it manually in any of the text editors.

#%RAML 1.0
title: TEST
baseUri: placeholder.example.com
description: API kit router test
mediaType: 
- application/json
version: "1"

/test:
  get:
    displayName: Get test
    description: API kit get test

  post:
    displayName: Post test
    description: API kit post test

  put:
      displayName: Put test
      description: API kit put test

  delete:
    displayName: Delete test
    description: API kit delete test
          
        
Create a new project in Mule.
Import or copy the API specification in “src/main/resources/api” folder.

Generate flows from the API specification file.
  • Right-click API Specification.
  • Select Mule.
  • Select Generate Flows from Local REST API.

Flows from the API specification will be generated, which you can check once the above step is done.
Auto generate flow
Configure HTTP listener.

Configure all flows unique to each HTTP method and URI. In this demo, I have configured the set payload for each unique HTTP method and URI combination.

API Tested in POSTMAN

Follow Me

If you like my post please follow me to read my latest post on programming and technology.

Instagram

Facebook

Recent Posts

Generate Parenthesis | Intuition + Code | Recursion Tree | Backtracking | Java

Problem Statement: Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. Example…

3 months ago

Square Root of Integer

Given an integer A. Compute and return the square root of A. If A is…

1 year ago

Build Array From Permutation

Given a zero-based permutation nums (0-indexed), build an array ans of the same length where…

1 year ago

DSA: Heap

A heap is a specialized tree-based data structure that satisfies the heap property. It is…

2 years ago

DSA: Trie

What is a Trie in DSA? A trie, often known as a prefix tree, is…

2 years ago

Trees: Lowest Common Ancestor

What is the Lowest Common Ancestor? In a tree, the lowest common ancestor (LCA) of…

2 years ago