Prototyping Web Services

An incorrect development cycle leads into inefficiency and high costs. We know what this means when we work developing mobile technologies, since there is an strict need to coordinate with more teams that deliver services to our applications.

We have came with the idea of mocking and prototyping our Backend services to speed up the development, and work parallelly with the Backend Team without creating a bottleneck until the services are delivered. For this purpose we have been using Apiary, which provides a great service but has two big limitations:

1.- Is not possible to test services that update an object in the server, such as PATCH or POST. We only receive the Mockups.
2.- We cannot filter requests based on different parameters (i.e., the content being sent is always static).

To overcome those limitations we will use Ruby on Rails (RoR). This is a web application framework written in Ruby, and is awesome. It allows you to create and deploy very easily web applications. I find it particularly cool when it comes to prototyping, since creating a web project takes the same effort as just writing the mockups in Apiary! It has many other cool features, such as autoa

We will introduce it with a very short example from a Coursera course. Let’s gonna create a basic blog application where we can store posts, and comments associated to those posts.

NOTE: RoR requires a set up on your computer that I will not cover in this article, but you can easily find instructions on the Internet.

The first step is to create the application with Ruby:

This will create a folder with the basic structure for the application.

Screen Shot 2014-09-22 at 2.00.58 PM

Our database will have two models: comments and posts. We will use scaffolds to create them:

Those two lines add the entities to our RoR application. We still need to add an association to them (a post can contain several comments). Let’s check in the folder of the application /app/models. There are two files, one for its entity. We will specify here the association between the models.

We will specify also that, if a post gets removed, the comments associated must also be removed.

Finally, with the following line we will transport those changes into our database schema.

And launch the application.

By default we can see it in http://localhost:3000/.Wwe can add posts or comments to the URL to display the particular entity. With only a few clicks, we have been able to construct a fully working application, with all the HTTP methods associated to them. If we type in the console rake routes all the routes and Entry Points of the application are displayed.

Screen Shot 2014-09-22 at 2.26.58 PM

Tags: , , ,

Leave a Reply

Name and Email Address are required fields. Your email will not be published or shared with third parties.