API Choice - JSON API V1 vs JSend

I am working on 2 Rails projects with APIs. Both applications use Grape mounted on Rails and swagger for documentation. The older TextbookValet.com API uses JSend based format for responses. The newer GivingFire.com API uses JSON API v1 compliant API. So what is the better option?


JSend dictates on the response format. It doss not provide any insight on how the API should behave or its format. One could argue its flexible. That is true. It allows you to architecture your API the way you desire.

Read more


JSON API v1 on the other hand dictates just about every thing. It is a huge document to read. At best its boring and most new developers find it confusing. But its weakness is its strength. The convention mens any developer familiar with the specification will quickly adopt to the API. There is also the possibility of automation.

Read more

Why I choose JSend

If you would have followed my posts, you will know I dislike fragmentation. A sister project of TextbookValet.com was already using JSend. Mobile developers would use both my project (Rails website) and the Java application. Since the Java developer had already implemented it and the client preferred it, I decide to follow her footsteps.

What happened…

Here is what happened. I left the TextbookValet.com team about 6 months ago. I was asked to implement some minor updates. When I came back Java Spring developer asked me a question. Following convention, I gave an answer without looking in the code. I was wrong. Had it been built on a strict set of rules, every one would know what does what.

This is exactly why I love Rails. In a well built app, you know where to find what thanks to the Rails way of doing things.


While there is no restriction. Following a recognized format is important in the long term. Think about tomorrow and implement your new API using JSON API v1. You will save your self a lot of trouble.

Ubuntu Timeout Outlook Mail

I am a freelance web developer. E Mail is a very important part of my business. But suddenly I was not able to access MS Outlook (web) in my Ubuntu machine. But then I heard the notification from my Windows box. I checked and both the Mail client and the web app were working fine.

I searched the web. A Ask Ubuntu answer said to setup the DNS server. That didn’t work for me.

Then I did a wget to find out if it was related to a browser.

wget https://outlook.office.com/?releam=jdeen.com

The output of wget suggested that it was getting redirected to https://login.microsoftonline.com. Then time outs.

Then I loaded the URL. After a few seconds of resolving domain name it redirected to the dashboard. I noticed that in the Windows machine the redirect is almost instantaneous. Not sure what is up. It looks like a DNS issue. How ever now I can check my mail.

Summary: Visit login.microsoftonline.com

MySQL Fix/Recover Root Password

John the CEO of TextbookValet.com asked if I would be able to help them with some updates to the site. I was previously in the team and I left there to join GivingFire.com. The app runs on MySQL. I hadn’t installed MySQL in my new computer so I did…

#~ sudo apt-get update
#~ sudo apt-get install mysql-server libmysqlclient-dev

I didn’t give a password in the installation pages. I actually didn’t even read what those messages said. When it was done, I tried to access the database and it said I couldn’t login. I red that newer version of MySQL would use the user password. So I tried my password with no luck. Then I tried the root password with no luck. I tried ‘password’ and had no luck. Then I decided to reset the password and figured some things had changed. So I thought of writing a blog post on how to.

First lets access the shell as root. We need root privileges to run the following commands.

#~ sudo -s

Then we need to start stop mysql and start it skipping auth checking.

#~ /etc/init.d/mysql stop
#~ mysql_safe --skip-grant-table &

Then we need to use the mysql database. There is a users table in it and we will update the password hash there. Now most documentation will say you need to update the password attribute but in newer versions of MySQL that is not the case. You need to update the authentication_string attribute. Also just to be safe, lets set the authentication method to use mysql_native_password. Here is how…

use mysql;
update user set authentication_string=PASSWORD('password') where user='root';
update user set plugin="mysql_native_password" where user='root';

Now that we have updated the password, we need to flush privileges and restart the server.

flush privileges;

Then in the shell…

#~ /etc/init.d/mysql stop
#~ /etc/init.d/mysql start

Now you can login with your password. Note: I used ‘password’ above for illustration purposes. Use a password of your choosing, the more secure the better.

I am 31

Birth is special, birthday isn’t, that is what I believe. What ever… it has been 31 years since a very confused me started breathing. 31 years and 9 months since I was commissioned. Here I am, wondering what the heck I am doing!

I haven’t celebrated my birthday since I turned 16. Since then I have given treats (cakes) 3 times. The first when I was an intern at Bank of Ceylon - Kurunegala. The other 2 times was my first and second year at University of Peradeniya.

Mum, S Z Bangsajayah, retired primary teacher at St. Anne’s College Kurunegala, wanted have a cake. So I got a cake, some sweets and candles ‘3’ and ‘1’. Took some photos. We had a small party and some visitors. I changed my policy, because I think it is time for me to change.

Rails & Slim - A match made in haven

Rails is about doing thins elegantly, with minimal code, in an extensible fashion. Slim is a template engine that transpile to HTML. Its minimal, elegant and fast. It makes boring HTML fun to write and easy to read! This document includes some helpful information about the world of Slim.


Slim has 2 install candidates. slim and slim-rails. If you are not on Rails, use the former. It will need some setup and config this document doesn’t cover.

Add slim-rails to your Gemfile and bundle.

# Gemfile
gem 'slim-rails'

This should do the trick. But for older versions I think you need to configure Rails to use Slim as the default template engine. If that is the case, do the following.

# config/application.rb
class Application < Rails::Application
  # Add the following
  config.generators do |g|
    g.template_engine :slim

Converting HTML / ERB to Slim

What if you already have your views in ERB? Or what if your designer provided you with HTML. This is more common than you think. Fortunately there is a tool for the rescue. It is html2slim. While the name suggests it converts HTML, it works fine for both HTML and ERB.

# Gemfile
group :development do
    gem 'html2slim'

This works fine 90% of the time flawlessly. Some times small portions of the conversion fails when it mistakes and adds Ruby in to some HTML attributes. I wanted to fix this long ago, but really didn’t find the time. Just delete the embedded Ruby and you will be fine.


I consider Slim a must in every new project I start. Then there is Haml. It takes a different approach to Slim. Many dislike HAML. How ever if you have an existing project in HAML, stick to it. Otherwise just jump shift to Slim!

Happy hacking!