If you need to iterate over a payload, a small payload is easy to write inline. Dealing with a large payload with arrays of objects with multiple properties things can get out of hand quickly.

I have been interfacing with a third party vendor's API to import orders from their system to ours. Normally that would not be an issue but their test environment was not very stable so all development requests needed to be routed through the production API endpoints while ensuring I did not go over the production rate-limit and bring down the application.

You know, Thursday.

Basically, I just want to be able to get the data from the call to make sure my processing works, I do not care about the actual content of the data as long as it was structrually correct. That got me thinking, API calls generally return JSON which can easily be stored as a text file.

Now if only there was a site that would allow you to easily share text files... Like GitHub, Stash, Gist, PasteBin or the myriad of other sites.

It just so happens I have a git repo containing API responses that I use as a reference when I am coding so I already have a good library, including several scenarios for listing orders.

The next step is getting that data in to ColdFusion using cfhttp and getting the raw resource and deserialize the JSON object. As a simple example of how this works here is a GitHub gist I made with 100 test posts from JSONPlaceholder.

 cfhttp(url = "https://gist.githubusercontent.com/robertz/a6dedfe698931745b4264ddef250e765/raw/99f2131b194c2da82c308d4d42730a44f0728190/posts.json");
 var posts = deserializeJSON(cfhttp.fileContent);
 writeDump(var = posts);

I was able to continue testing my order processing routine without having to call the production API. It also allowed me to go off the "happy path" since I am controlling the data.

I do not know if anyone else will find this useful but I have been using it quite a bit the last few days.

Happy Friday!