small medium large xlarge

23 Oct 2013, 18:49
Jeremy Hartley (2 posts)

When I follow the code samples in the book and use RSpec for testing the basic CRUD API works fine.

However when I try to use Advanced REST Client in Chrome for testing either the POST or the PUT then I ran into some issues.

If I e.g. POST the following JSON:

{“url”:”url1”, “title”:”title1”}

to http://localhost:4567/bookmarks using Content-Type: application/json then the params is empty.

After doing some research I was able to solve this by adding the following line at the start of the POST handler.

params = JSON.parse(

This works all good and well with my REST Client, but it breaks RSpec.

Does anybody have any clues on what I am doing wrong?

30 Oct 2013, 14:33
Fred Daoud (22 posts)

In the basic crud example of the Sinatra chapter, params is used which means you need to send the data in request parameters, i.e. ?url=url1&title=title1. In the Sinatra server from the AngularJS chapter, the body is used instead of the request parameters, and uses JSON.parse(

So it’s just a question of request parameters vs request body.

Hope that helps. Cheers, Fred

30 Oct 2013, 19:30
Jeremy Hartley (2 posts)

Thanks Fred. That clarifies things a bit. The fact that this was a POST made me assume that the body should be used and not a querystring.

You must be logged in to comment