Another project another blog post. Here for this project we at Turing had to incorporate JSON formatting using fast_json for out API that we were designing. This is honestly one of the most challenging things that I have had to do at Turing thus far. The reason for the challenge is that there are a lot of moving parts to setting up your API to respond correctly. So in the spirit of that I would like to just quickly mention in a step by step process how I implemented it.
Set up your rails project and use any options you might require for database or testing. But in the command for the new app make sure — — api is called in the creation.
Add the fast_json gem to your gem file and read the documentation to learn to set up your serializers. A Serializer in rails allows us to control out endpoints for out data as well as will format the data into JSON format per the documentation.
Namespace the routes under the ‘api’ and version namespaces.
Look up the documentation on how to test you new and running api as you design it moving forward.
Those are the quick and dirty steps to get yourself an API running in less than an hour. There is a ton more that is worth going into but I would like to close out by reflecting on the project looking at my struggles, my successes and finally what I would do differently moving forward.
I actually found setting up and using an API to be fairly straight forward as far as I got.
I really enjoyed this project for how little time I had on it and plan on finishing it over the module here at Turing provided I have time.
A single typo cost me way too much time on this. I need to remember that a strange error often means a spelling or capitalization issue.
Did not get to do my favorite part of this project which is usually the ActiveRecord.
As mentioned above I found the setup and understanding of what was going on straight forward but failed to account for how long it was going to take to get it all set up for the first time
I need to find a better way for troubleshooting strange errors that cost time in the future. Otherwise it is hard to fault my lack of time on poor time management as this project is mostly incomplete due to some unforeseen health issues.