Search engine

This functionality allows you to search for responses in JSON format, based on URI parameters.

To work with the search engine, you need to use URI segments of the format {<keyInYourJson>} - for required parameters {<keyInYourJson>?} - for optional parameters.

How to work with it

Let's create an endpoint with a GET method and the path /user/transaction/{id?}

The response body will look like this:

{
  "message": null,
  "response": [
    {
      "id": 1,
      "amount": "10.36",
      "ticker": "USD"
    },
    {
      "id": 2,
      "amount": "23.01",
      "ticker": "EUR"
    }
  ]
}

As you can see, my parameter is named id, which is identical to the JSON key of the object that is in my response body. The search will work exactly according to the values ​​of these id keys in each JSON object.

Search logic

After entering the URI parameter for the search, a window with settings appears.

Path

Path to a JSON array containing the objects to be searched. In our example, the array of objects is located at level 1, in the response key, in this Path field we write the name of this key - response.

Possible cases:

  1. The array of objects is at level 0 - then the Path field will be empty

  2. The array of objects is at level 2 or more - then the Path field will contain: <firstKey>.<secondKey>.<thirdKey> ...

Result format

Let's look at 2 options for displaying results:

  1. Array of objects (even if 1 object). The search result will be wrapped in an array, even if one JSON object is found.

  2. Just an object (if more than 1 object is found, only the first one will be displayed).

Testing

Case 1 - I don't pass the parameter because it's optional

GET https://xxxxxxxx-mock.migratech.cloud/user/transaction
// Result format - no difference because there is no URI parameter
{
  "message": null,
  "response": [
    {
      "id": 1,
      "amount": "10.36",
      "ticker": "USD"
    },
    {
      "id": 2,
      "amount": "23.01",
      "ticker": "EUR"
    }
  ]
}

Case 2 - I pass a parameter whose value is in one of the objects

GET https://xxxxxxxx-mock.migratech.cloud/user/transaction/1
// Result format - Array of objects
{
  "message": null,
  "response": [
    {
      "id": 1,
      "amount": "10.36",
      "ticker": "USD"
    }
  ]
}

// Result format - Just an object
{
  "message": null,
  "response": {
    "id": 1,
    "amount": "10.36",
    "ticker": "USD"
  }
}

Case 3 - I pass a parameter whose value is not in the objects

GET https://xxxxxxxx-mock.migratech.cloud/user/transaction/3
// Result format - Array of objects
{
  "message": null,
  "response": []
}

// Result format - Just an object
{
  "message": null,
  "response": null
}

Last updated

#20:

Change request updated