In the last article, you can find the idea of how to introduce field filtering for your APIs. My simplified Content Filter allows for providing negative or positive filtering. The first one tells which fields Filter removes from the target response. The latter one tells which fields should be available in the response. Today I show you how I have implemented this using DataWeave language.

Filterable DataWeave Module

Okay, our input is straightforward. The Content Filter has two input arguments, like in the diagram below

content filter

Input argument for the Content Filter.

Filter Parameter

As you remember, we should be able to do positive or negative filtering. We can filter many fields that are in a comma-separated form. In order to distinguish negative filtering, each field should have a minus prefix like -type. In the case of positive filtering, no prefix is required.

I have also introduced *all keyword as a default one to represent the idea of all fields. We can combine it with both filters. Below you can see two ways of removing single type property from the object:

Java

1

*all,-type

2

-type

#tutorial #integration #rest #mulesoft #dataweave #filter parameter

Content Filter Pattern for REST Service — Implementation
1.30 GEEK