Revisiting Volley Requests’ REST support


We have already discussed our Volley Requests library. Over a year ago, we built REST support into it. In hindsight, we didn’t get the API perfectly. That’s why we decided to make a new iteration of it based on Restangular.

We realized that our first approach, required you to repeat a lot of slightly different code for different object types. We weren’t happy with this and decided to go back to the drawing board. We looked around at other REST library APIs, and settle down on doing something similar to what Restangular does. It is flexible and very simple to use, using method chaining to configure just what you need. It also provides a sweet set of optional features, unique to our api.

How do you use it?


I’m not going to overwhelm you with too much technicality, just a few examples and a “need-to-know” basis so you get the feeling of our api.

We provides direct methods for GET, POST, DELETE, etc. combined with method chaining, allowing for a very intuitive use.

Suppose you need a request to retrieve one specific resource like this GET http://myurl.com/me , you first set your base URL

Then, you literally tell Rest to “get” your one resource.

I know what you are thinking, “Who the hell goes through all that trouble for a simple URL?”. Wait, there is more! Queries can make our requests increasingly more complex, thus making them harder to build, but don’t worry, our design gracefully takes care of that as well.

Let’s get more specific. Suppose you want to add a new character through POST method to your list of favorite TV characters for a specific TV show. Let’s also assume that you need some sort of authentication. Naturally, you are going to add a token to your query, leaving the URL something like this:

http://myurl.com/TV/shows/Game%20of%20Thrones/characters/favorites?token=authentication_token

Look how simple it is:

I know, right? You can literally make thousand of variations by adding few and simple lines of code. Like here for instance, where you try to remove a character from the list of favorites characters. You could use DELETE method.

Extra Features


Last but not least, there is the Interceptor that intercepts (really? who would have known…) the request every time before processing it, to dynamically change it (another idea borrowed from Restangular). You can customize it any shape or form, buy simply implementing its intercept() method. Suppose you need all your requests signed for security purposes, instead of adding your signature by hand every single time, the Interceptor will do it for you. Sweet!

Still here? Great, that means I’ve caught a bit more than just your attention. But hey, don’t take my word for any of these, you should see it for yourself! Here is our project so you can check it out! Feel free to explore, use and collaborate in any way you like, feedback is much appreciated. Go nuts! :)


If you like what you’re reading, and would like to work with us write to jobs at monits dot com with subject “Medium — Job opportunity”.