Monday, 10 March 2025

Can Traffic Parrot return binary files in responses?

 "Can an HTTP response in Traffic Parrot contain a binary file?" - software developer working for an e-commerce company.

Yes.

The simplest way to create a mock in Traffic Parrot that returns a binary file in the response is to create that mock by doing a recording. That assumes you have a real service that you can record.

If you don't have a real service that returns the binary file in the response, you can create a mapping manually. To do that:

  1. Create a file in trafficparrot-x.y.z/mappings directory called, for example mapping-dummy-file.json
  2. The mapping-dummy-file.json should contain the following (notice the reference to body-dummy-file.pdf): 
    {
      "id" : "5d6a8f32-914c-4b67-ae15-f2c9d7b3e091",
      "name" : "mapping-dummy-file.json",
      "request" : {
        "url" : "/dummy.pdf",
        "method" : "GET"
      },
      "response" : {
        "status" : 200,
        "bodyFileName" : "body-dummy-file.pdf",
        "headers" : {
          "Content-type" : "application/pdf"
        }
      }
    }
  3. Create the binary response body file body-dummy-file.pdf in trafficparrot-x.y.z/__files. You can use any PDF file just make sure the filename is specified in the mapping json file in bodyFileName attribute
  4. Now if you visit http://localhost:8081/dummy.pdf then a PDF binary file will be returned. 

No comments:

Post a Comment