coding and cooking

Awesome RESTful API with Rails

Awesome RESTful API with Rails

If you are coding in Ruby with Rails, at some moment inexorably you will need to build a RESTful API, to respond some external HTTP requests. So, let's consider to create a JSON API and let's do this with elegance and the right way, i.e., testing!



For this post, I'm using:

So, basically, our task will be to send HTTP requests and test the response status code for each one and it's body contents; it needs to match our expectations.

The app I created for this post is in a repository on Github. It's a products managing example app.

What we want to test?

As said previously, we will focus in two things: the response body and status code of it. I think this is the most important stuff of a good API application test. Testing the body we testify if our application is sending the right content, if it's possible. What you mean with...

Read more