Nav

To Dynamically Change the URL of a Request (Design Center)

This procedure builds on the procedure that creates a basic Mule app. In that app, you requested data from a particular URL of a REST service. Now, you change the app to make a request to the URL you specify on-the-fly when you start the app. You configure the HTTP Request path using an expression. In the expression, you use the keyword from the query string that starts the app from a browser:

/getpath?keyword=users

where

  • getpath is the value of Path in the listener configuration.

  • users is the path known to the JSON Placeholder service that returns user data.

    1. Open myproject, and in the Consume API Flow, open HTTP Request.

      change http request configuration
    2. Click Change to change the configuration of HTTP Request.

      • In General, in Path, click Function f of x key.

      • Type the following text:

        attributes.

        Pause to see a list of options.

        list of available options for entry
      • Select queryParams, and then type a period followed by this keyword:

        path

        For example:

        attributes.queryParams.path

        attributes queryParams path
    3. Click Deploy, and execute the flow:

      • When deployment is complete, click options run app design env design center 2428b > Copy Link.

      • Paste the link in a browser or client, and add the following path to the end of the link:

        /getpath?path=todos

        The HTTP Listener hears the request, and starts the app. The list of todos appears in the browser.

        [
          {
            "userId": 1,
            "id": 1,
            "title": "delectus aut autem",
            "completed": false
          },
          {
            "userId": 1,
            "id": 2,
            "title": "quis ut nam facilis et officia qui",
            "completed": false
          },
        ...
    4. Close HTTP Request.

      The green status indicator appears in all parts of the flow.

    5. Change the path of the URL to get the users.

      /getpath?path=users

      [
        {
          "id": 1,
          "name": "Leanne Graham",
          "username": "Bret",
          "email": "Sincere@april.biz",
          "address": {
            "street": "Kulas Light",
            "suite": "Apt. 556",
            "city": "Gwenborough",
            "zipcode": "92998-3874",
            "geo": {
              "lat": "-37.3159",
              "lng": "81.1496"
            }
          },
      ...
    6. Change the URL to get the posts.

      /getpath?path=posts

      Now, you’re ready to inspect input and output payloads and attributes.

In this topic: