Json Path Assertion

JSON Path Assertion: Easily create JSON Path tests for your API responses using both SDKs and REST APIs. Just provide your API response to begin.

Usage 🚀

Refer to Setup Guide for installing dependecies for both Java and Python.

JAVA

There are 2 clients available with the Java SDK: SyncClient and AsyncClient

chevron-rightJava Client Codehashtag
# for async client 
import org.qyrus.ai_sdk.Clients.AsyncClient;
AsyncClient client = new AsyncClient(<API_TOKEN>, null);

# for sync client
import org.qyrus.ai_sdk.Clients.SyncClient;
SyncClient client = new SyncClient(<API_TOKEN>, null);

Using SyncClient

Here's an example of utilizing JSON Path Assertion with SyncClient.

chevron-rightJava SyncClient Codehashtag
private static void testJSONPathAssertion() {
        Dotenv dotenv = Dotenv.load();
        String QYRUS_AI_SDK_API_TOKEN = dotenv.get("QYRUS_AI_SDK_API_TOKEN");

        SyncClient client = new SyncClient(QYRUS_AI_SDK_API_TOKEN, null);
        Map<String, Object> loanApplication = Map.of(
        "loanId", 101,
        "userId", 1,
        "loanAmount", 200000,
        "loanTerm", 30,
        "propertyValue", 250000,
        "income", 100000,
        "creditScore", 750,
        "status", "pending"
    );

        long startTime = System.currentTimeMillis();
        int numberOfRequests = 2;
        
        for (int i = 0; i < numberOfRequests; i++) {
            try {
                // Assuming that the client has an appropriate method for JSON body assertions
                JSONPathAssertion.JsonPathAssertionResponse response = client.api_assertions.jsonpath.create(loanApplication);
                
                // Process and print JSON body assertions
                for (JSONPathAssertion.Assertion assertion : response.getAssertions()) {
                    System.out.println(assertion.getJsonPath());
                    System.out.println(assertion.getJsonPathValue());
                    System.out.println(assertion.getType());
                    System.out.println(assertion.getAssertionDescription());
                }
                
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        
        long endTime = System.currentTimeMillis();
        System.out.println("Synchronous Total time for JSON Path Assertion request: " + (endTime - startTime) + " ms");
    }

Using AsyncClient

Here's an example of utilizing JSON Path Assertion with AsyncClient.

chevron-rightJava AsyncClient Codehashtag

PYTHON

There are two clients available with the Python SDK: SyncQyrusAI and AsyncQyrusAI.

chevron-rightPython Client Codehashtag

Using SyncQyrusAI

Here's an example of utilizing JSON Path Assertion with SyncQyrusAI.

chevron-rightPython SyncQyrusAI Codehashtag

Using AsyncQyrusAI

Here's an example of utilizing JSON Path Assertion with AsyncQyrusAI.

chevron-rightPython AsyncQyrusAI Codehashtag

REST APIs

This API allows users to create test based on provided API JSON Path.

  • Endpoint

    • URL : POST {{GATEWAY_URL}}/api-assertion-gpt-sdk/v1/api/assertion/jsonpath

  • Headers

    • Authorization: [Your Authorization Token]

    • Custom: [Your Custom Header Value]

  • Request Body: { "response": { "loanId": 101, "userId": 1, "loanAmount": 200000, "loanTerm": 30, "propertyValue": 250000, "income": 100000, "creditScore": 750, "status": "pending" } }

  • Response:

Last updated