Contact Free trial Login

To Filter Users By ID Using a Parameter

This procedure shows how to set up query parameters to filter data consumed by the API. Showing query parameters was chosen for example purposes instead of the conventional approach of using a path segment to get the unique identifier of a user. In the procedure, you add logic to the API to return information about user having ID = n.

Revise the flow to filter users by ID:

  1. Drag an HTTP Listener component from the Mule palette to the Source section of the get:/users/userbyid:api-config flow.

  2. In the Listener properties editor, in Connector Configuration of the HTTP Listener, select api-httpListenerConfig.

    Click Edit-16x16, and then OK to accept the default host 0.0.0.0 and port 8081.

  3. In the Listener properties editor, in General, set Path to /placeholder/byid.

  4. Remove Transform Message from the Process area.

  5. Drag an HTTP Request component to the Process area to the left of Transform Message.

  6. In Configuration, select HTTP_Request_configuration. Click Edit-16x16, and accept the default settings:

    • Host = jsonplaceholder.typicode.com

    • Port = 80.

      Click OK.

  7. In the properties editor, in General, set these HTTP Request options:

    • Path: Set to /users.

    • Method: Accept the default method GET.

    • Select the Query Parameters tab, click Add-16x16, and replace "key" and "value" with the following name and value (no quotation marks):

      • Name: id

      • Value to attributes.queryParams.id

      • Accept the other defaults.

        apikit query parameter
  8. In the properties editor, set metadata properties as follows:

    • Select Metadata.

      apikit metadata
    • Declare the data type of the id as follows:

      • Select Input: Payload from the drop-down.

      • Name the type using an arbitrary name, for example, int-type.

      • Define the type as an integer.

        apikit set payload type
  9. Save all.

Next, add a service to get only user names

Was this article helpful?

💙 Thanks for your feedback!

Edit on GitHub