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

Find Intersection of Two Singly Linked Lists

You are given two singly linked lists that intersect at some node. Your task is…

3 months ago

Minimum Cost to Paint Houses with K Colors

A builder plans to construct N houses in a row, where each house can be…

3 months ago

Longest Absolute Path in File System Representation

Find the length of the longest absolute path to a file within the abstracted file…

3 months ago

Efficient Order Log Storage

You manage an e-commerce website and need to keep track of the last N order…

4 months ago

Select a Random Element from a Stream

You are given a stream of elements that is too large to fit into memory.…

4 months ago

Estimate π Using Monte Carlo Method

The formula for the area of a circle is given by πr². Use the Monte…

4 months ago