0

What are the best ways to Automate JSON POST Request using Restassured API.

My POST request is too big and all my endpoints requests are too bit.
Appreciate your help on this.

For Ex:

{
      "async": false,
      "shipper_accounts": [
        {
          "id": "00000000-0000-0000-0000-000000000000"
        }
      ],
      "is_document": false,
      "shipment": {
        "ship_from": {
          "contact_name": "Elmira Zulauf",
          "company_name": "Kemmer-Gerhold",
          "street1": "662 Flatley Manors",
          "country": "HKG",
          "type": "business"
        },
        "ship_to": {
          "contact_name": "Dr. Moises Corwin",
          "phone": "1-140-225-6410",
          "email": "Giovanna42@yahoo.com",
          "street1": "28292 Daugherty Orchard",
          "city": "Beverly Hills",
          "postal_code": "90209",
          "state": "CA",
          "country": "USA",
          "type": "residential"
        },
        "parcels": [
          {
            "description": "Food XS",
            "box_type": "custom",
            "weight": {
              "value": 2,
              "unit": "kg"
            },
            "dimension": {
              "width": 20,
              "height": 40,
              "depth": 40,
              "unit": "cm"
            },
            "items": [
              {
                "description": "Food Bar",
                "origin_country": "USA",
                "quantity": 2,
                "price": {
                  "amount": 3,
                  "currency": "USD"
                },
                "weight": {
                  "value": 0.6,
                  "unit": "kg"
                },
                "sku": "imac2014"
              }
            ]
          }
        ]
      }
    }
  • Too big for reading or what? – dzieciou Aug 1 '18 at 19:04
2

You need to apply the below areas to your framework:

  • The body for the POST call should be coming from a model file. Use a java serialization/de-serialization library like jackson or Gson to achieve this, although RestAssured has this feature. Creating complex json becomes easier.
  • Create a RequestSpecBuilder to create the POST call, so that you can reuse this for each time you are making a POST call.

Right now I have these two points in my mind.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.