JavaScript is required to use Bungie.net

OffTopic

Surf a Flood of random discussion.
12/2/2014 11:04:24 PM
0

Today, I wrote a JSON serializer that does nothing.

Warning, developer commentary inbound. I've been working on a tool to help test out a RESTful API we've been cooking up at work. I'd gotten the layout and the design where I wanted it to be and I hooked up the bits and pieces of the UI so they all work and play nice together. Good deal, job well done. For the inside giblets, I used RestSharp to handle the creation, execution, and response monitoring of the requests being made upon the target API. Once I knew where the payload was supposed to end up, the application would grab that pristinely formatted string of perfectly valid JSON that the application itself stored, to be generated and modified by the person testing the endpoint. Simply, the app generated valid text that could be tested against an API. The first few tests revealed that there was an issue with RestSharp's handling of a pre-existing JSON string. It claimed that one and only one object could inhabit the Body of the request. I obliged by breaking down the user input into smaller chunks -- key-value pairs -- that would then be added to the request as Parameters. It appeared that I'd resolved the issue, as the target API began to send responses indicating that it had accepted the request and that all was well. A short time later, I began to receive failure responses from the API. The target claimed that items I'd used constituted invalid parameters. A colleague and I hopped on Wireshark and Fiddler and began to monitor traffic. He pointed out that something was cutting off the second input parameter in the request and I validated this with my own readings. Fearing some artifacts or input contamination, I scoured the application for defects, but to no avail. I began work on a method to parse the JSON string into its necessary components to perhaps work around the issue of Bodies and Parameters by simply concatenating the Url string with the proper keys and values. This I did most begrudgingly, as I was churning up simple, valid text through additional code, all of which would need to be unit tested once I figured out if it would work or not. Then, as I was browsing through the original documentation, I re-read that phrase that haunted the original idea to use the AddBody method to add a Body to the request. It was then and only then that I realized that I could write my own serializer to parse the data coming into that method. Of course, that method would simply return the original data, since it's already functional JSON. It works like a charm. Today, I wrote a JSON serializer that does nothing. :) -Federal

Posting in language:

 

Play nice. Take a minute to review our Code of Conduct before submitting your post. Cancel Edit Create Fireteam Post

You are not allowed to view this content.
;
preload icon
preload icon
preload icon