Appian Community and Appian Academy are being upgraded. As a part of the upgrade, Appian Community is currently in read-only mode, and user registration is disabled until August 3. We apologize for any inconvenience this may cause, but a more secure, stable, and performant Community experience is coming soon!

The new Appian Community launches August 3, followed by Appian Academy on August 7. During the migration, Appian Community Edition, Appian Academy, Documentation, Certifications, Instructor-led Customer Training, Partner Sales Training & Accreditation, and Forum (for Appian Partners and Customers only) will remain available.

Best Way to mock or stub an integration ( How to set httpResponse object on a dictionary on the fly) inside an expression rule

Hi,

       I am trying to stub / mock an api response for an http Integration in a expression rule . Basically I am trying to a create a dictionary like what we get on a successful response from an api like below structure

Dictionary

    • success  -   true(Boolean)
        • result   -    HttpResponse

        I am able to get first key (success - true) using a!fromJson , but cant find a way to set a successful HttpResponse object to result key through  the code . I tried to use a!httpResponse , but it creates a webapiResponse .

        I can see an IntegrationError Object to create such an object for error scenarios. But why there is no IntegrationSuccess object similar to this ?

        a!fromJson(
          "{""success"":true}"
        )

         

          Discussion posts and replies are publicly visible

        Parents
        • 0
          Certified Lead Developer

          You cannot manually construct a true HttpResponse object. It's only created by the system when an integration executes.
          Define your mock as a plain dictionary structure that mimics the HttpResponse shape:

          a!localVariables(
            local!mockResponse: a!map(
              statusCode: 200,
              headers: a!map(),
              body: /* your mock data */
            ),
            /* use local!mockResponse in your logic */
          )


          Then write your consuming code to handle either a real HttpResponse or your mock dictionary structure interchangeably.

        Reply
        • 0
          Certified Lead Developer

          You cannot manually construct a true HttpResponse object. It's only created by the system when an integration executes.
          Define your mock as a plain dictionary structure that mimics the HttpResponse shape:

          a!localVariables(
            local!mockResponse: a!map(
              statusCode: 200,
              headers: a!map(),
              body: /* your mock data */
            ),
            /* use local!mockResponse in your logic */
          )


          Then write your consuming code to handle either a real HttpResponse or your mock dictionary structure interchangeably.

        Children
        No Data