background preloader

Apis

Facebook Twitter

Google maps api

Grape | REST-like API micro-framework. What is Grape? You don't need a hand saw to slice an apple. And you don't need to use Rails to write simple APIs. Grape allows you to build lightweight APIs with Ruby when you don't need the heavy lifting power of large frameworks like Rails. It's a REST-like API micro-framework built to complement existing web application frameworks by providing a simple DSL to easily provide APIs. It has built-in support for common conventions such as multiple formats, subdomain/prefix restriction, and versioning. Who's Using Grape? With over 2000 watchers and 200 forks on Github, Grape is powering numerous web applications including Elevate, a state of the art POS system from Agilysys, and Artsy.net, a free and open-access platform application funded by leading visionaries in the tech industry that aims to make art accessible to anyone with an Internet connection.

Getting Started Grape is available as a gem, to install it just install the gem: gem install grape gem 'grape' Resources Created By: @mbleigh. API with Ruby on Rails: useful tricks | Railsware Blog. This article is about gotchas you should be aware of while building your API with Ruby on Rails. Controller tricks: API on Metal Sooner or later each Rails developer come to a point when he wants to build his first API. Among the first things you have to take care of are your controllers. If you want your API to be fast (and I bet you do) then you should consider using ActionController::Metal. The trick is that ActionController::Base has many Middlewares that are not necessary for the API, by using Metal controller with minimum modules included, the one can achieve up to 40% speedup. Lets see what your basic metal controller may looks like: Unfortunately NewRelic doesn’t support Metal by default, so you have to add monitoring manually.

Routing: use versioning Nobody’s perfect. Namespace :api do namespace :v1 do # put your routes here end end Views tricks: RABL ‘em all You don’t want to burden your code with logic of exposing different model fields for different API actions, right? Security. Writing an API Wrapper in Ruby with TDD. Sooner or later, all developers are required to interact with an API. The most difficult part is always related to reliably testing the code we write, and, as we want to make sure that everything works properly, we continuosly run code that queries the API itself. This process is slow and inefficient, as we can experience network issues and data inconsistencies (the API results may change). Let’s review how we can avoid all of this effort with Ruby.

"Flow is essential: write the tests, run them and see them fail, then write the minimal implementation code to make them pass. Once they all do, refactor if needed. " Our goal is simple: write a small wrapper around the Dribbble API to retrieve information about a user (called ‘player’ in the Dribbble world). The Dribbble API is fairly straightforward. This tutorial needs to assume that you have some familiarity with testing concepts: fixtures, mocks, expectations.

To summarize here, here are three key concepts you must know: