{"id":4508,"date":"2013-04-08T12:02:55","date_gmt":"2013-04-08T09:02:55","guid":{"rendered":"http:\/\/railsware.com\/blog\/?p=4508"},"modified":"2026-06-16T15:48:51","modified_gmt":"2026-06-16T12:48:51","slug":"api-with-ruby-on-rails-useful-tricks","status":"publish","type":"post","link":"https:\/\/railsware.com\/blog\/api-with-ruby-on-rails-useful-tricks\/","title":{"rendered":"API with Ruby on Rails: useful tricks"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">This article is about gotchas you should be aware of while building your API <a href=\"https:\/\/railsware.com\/blog\/ruby-on-rails-guide\/\">with Ruby on Rails<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Controller tricks: API on Metal<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Sooner or later each <a href=\"https:\/\/railsware.com\/blog\/how-to-hire-good-ruby-on-rails-developer\/\">Rails developer<\/a> come to a point when he wants to build his first API.<br>Among the first things you have to take care of are your controllers.<br>If you want your API to be fast (and I bet you do) then you should consider using <a href=\"http:\/\/weblog.rubyonrails.org\/2008\/12\/17\/introducing-rails-metal\/\">ActionController::Metal<\/a>.<br>The trick is that <code class=\"\" data-line=\"\">ActionController::Base<\/code> has many Middlewares that are not necessary for the API, by using Metal controller with minimum modules included, the one can achieve <a href=\"https:\/\/gist.github.com\/738168\">up to 40% speedup<\/a>.<br>Lets see what your basic metal controller may looks like:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">class Api::V1::BaseController &lt; ActionController::Metal\n  include ActionController::Rendering        # enables rendering\n  include ActionController::MimeResponds     # enables serving different content types like :xml or :json\n  include AbstractController::Callbacks      # callbacks for your authentication logic\n\n  append_view_path \"#{Rails.root}\/app\/views\" # you have to specify your views location as well\nend<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Unfortunately NewRelic doesn&#8217;t support Metal by default, so you have to <a href=\"https:\/\/newrelic.com\/docs\/ruby\/adding-instrumentation-to-actioncontroller-metal\">add monitoring manually<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Routing: use versioning<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Nobody&#8217;s perfect. So are we.<br>Your API will definitely be changed and extended multiple times in the future so you better take care of your versioning at the beginning.<br>As you noticed, <code class=\"\" data-line=\"\">BaseController<\/code> wrapped in <code class=\"\" data-line=\"\">V1<\/code> namespace. Use something like this in your routes:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">namespace :api do\n  namespace :v1 do\n    # put your routes here\n  end\nend<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Views tricks: RABL &#8217;em all<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">You don&#8217;t want to burden your code with logic of exposing different model fields for different API actions, right?<br>In this case you should use some template engine. <a href=\"https:\/\/github.com\/nesquena\/rabl\">RABL<\/a> is at your service. Here&#8217;s an example of your view:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">object @object\n\nattribute :public_id => :id\nattributes :title, :created_at, :source\n\nchild :contacts do\n  attributes :title\nend\n\nchild :files do\n  attributes :filename, :content_type, :size\nend<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Also that will save you time by getting rid of ugly <code class=\"\" data-line=\"\">respond_to<\/code> blocks. Instead of<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">def show\n  @object = Object.find(params[:id])\n  respond_to do |f|\n    f.json { render json: @object.to_json }\n    f.xml  { render xml: @object.to_xml }\n  end\nend<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">You can simple do literally Nothing<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">def show\n  @object = Object.find(params[:id])\nend<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Just make sure you have a RABL view in a corresponding directory.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Security<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">There&#8217;re plenty of articles about API security best practices with OAuth. Another convenient way is to simply use token passed in the query string. If you ended up with token keep in mind that you can easily generate it by calling <code class=\"\" data-line=\"\">SecureRandom.urlsafe_base64<\/code>. To make sure token is unique you can use something like this:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">def build_token\n  begin\n    token = SecureRandom.urlsafe_base64\n  end while User.exists?(api_token: token)\n  token\nend<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Hiding your IDs with GUIDs<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">By default Rails uses incremental integer for primary key.<br>Common practice is not to expose these kind of IDs to the public via your API because users can guess other IDs in your database and that might be a potential risk.<br>To solve this you can come up with a simple algorithm that will convert your IDs into some &#8220;safe&#8221; form and back.<br>But still it&#8217;s not super safe because someone can find out what the algorithm is.<br>Another possible solution is to expose <a href=\"http:\/\/en.wikipedia.org\/wiki\/Globally_unique_identifier\">GUIDs<\/a> to the public.<br>It&#8217;s a 128 entity that typically looks like this:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">To generate it in Ruby use <code class=\"\" data-line=\"\">SecureRandom.uuid<\/code> (generates V4 GUID).<br>You can store it as a simple string column but if you are using Postgresql then you can utilize it&#8217;s built in <code class=\"\" data-line=\"\">uuid<\/code> type &#8211; this can <a href=\"http:\/\/simononsoftware.com\/how-to-store-uuids-in-postgresql\/\">save you a lot of space<\/a>.<br>Rails, however falls back to <code class=\"\" data-line=\"\">:string<\/code> for the <code class=\"\" data-line=\"\">uuid<\/code> Postgresql native type.<br>To workaround this you can create column manually in your migration (index should be added as well):<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">execute \"ALTER TABLE objects add COLUMN public_id uuid NOT NULL DEFAULT uuid_generate_v4()\"\nadd_index :objects, [:public_id], name: \"index_objects_on_public_id\", unique: true<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">To use <code class=\"\" data-line=\"\">uuid_generate_v4<\/code> function you have to add Postgresql extension:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">create extension \"uuid-ossp\"<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">And don&#8217;t forget to change your schema format to <code class=\"\" data-line=\"\">:sql<\/code> in <code class=\"\" data-line=\"\">config\/application.rb<\/code><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">config.active_record.schema_format = :sql<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Testing your API<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">You definitely want to cover up your new shiny API with some sort of tests. See example below that uses <code class=\"\" data-line=\"\">Rack::Test::Methods<\/code><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"># spec_helper\nmodule ApiHelper\n  include Rack::Test::Methods\n\n  def app\n    Rails.application\n  end\nend\n\nRSpec.configure do |config|\n  config.include ApiHelper, api: true\nend\n\n# spec\nrequire 'spec_helper'\n\ndescribe \"api\/v1\/objects\", api: true do\n  let(:url) { \"api\/v1\/objects\" }\n  let(:object) { Factory.create(:object) }\n  let(:token) { \"YOUR_SECRET_TOKEN\" }\n  let(:data) { JSON.parse(last_response.body) }\n\n  before(:each) { get url, token: token }       # here's where API call made\n\n  subject { data }\n\n  it { should have(1).object }\nend<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">We&#8217;ve just gone through the following tricks:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Minimum usable Metal controller<\/li>\n\n\n\n<li>Simple versioning<\/li>\n\n\n\n<li>Easy API views with RABL<\/li>\n\n\n\n<li>Postresql native <code class=\"\" data-line=\"\">uuid<\/code> type<\/li>\n\n\n\n<li>API spec sample<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Sure, you&#8217;ll face a lot more issues in the wild but these basics intended to help you start up quickly.<br>The last, but not the least &#8211; don&#8217;t forget about good documentation. Your API users will definitely appreciate it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If you want to try all these tricks in the wild see recently released API for our <a href=\"https:\/\/mailtrap.io\">dummy SMTP server &#8211; Mailtrap.io<\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><b>UPDATE<\/b><br>If you want to use <code class=\"\" data-line=\"\">render json: your_json<\/code> you should <code class=\"\" data-line=\"\">include ActionController::Renderers::All<\/code> in your base API controller. Thanks <b>Divya Kunnath<\/b> for pointing that out.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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&#8230;<\/p>\n","protected":false},"author":34,"featured_media":9484,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"inline_featured_image":false,"footnotes":""},"categories":[3],"tags":[],"coauthors":["Innokenty Mihailov"],"class_list":["post-4508","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-development"],"acf":[],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 4.9.9 - aioseo.com -->\n\t<meta name=\"description\" content=\"This article is about gotchas you should be aware of while building your API with Ruby on Rails.\" \/>\n\t<meta name=\"robots\" content=\"max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n\t<meta name=\"author\" content=\"Innokenty Mihailov\"\/>\n\t<link rel=\"canonical\" href=\"https:\/\/railsware.com\/blog\/api-with-ruby-on-rails-useful-tricks\/\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 4.9.9\" \/>\n\t\t<meta property=\"og:locale\" content=\"en_US\" \/>\n\t\t<meta property=\"og:site_name\" content=\"| Blog on Engineering, Product Management, Transparency, Culture and many more...\" \/>\n\t\t<meta property=\"og:type\" content=\"article\" \/>\n\t\t<meta property=\"og:title\" content=\"API with Ruby on Rails: useful tricks | Railsware Blog\" \/>\n\t\t<meta property=\"og:description\" content=\"This article is about gotchas you should be aware of while building your API with Ruby on Rails.\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/railsware.com\/blog\/api-with-ruby-on-rails-useful-tricks\/\" \/>\n\t\t<meta property=\"og:image\" content=\"https:\/\/railsware.com\/blog\/wp-content\/uploads\/2013\/04\/API-with-Ruby.png\" \/>\n\t\t<meta property=\"og:image:secure_url\" content=\"https:\/\/railsware.com\/blog\/wp-content\/uploads\/2013\/04\/API-with-Ruby.png\" \/>\n\t\t<meta property=\"og:image:width\" content=\"360\" \/>\n\t\t<meta property=\"og:image:height\" content=\"360\" \/>\n\t\t<meta property=\"article:published_time\" content=\"2013-04-08T09:02:55+00:00\" \/>\n\t\t<meta property=\"article:modified_time\" content=\"2026-06-16T12:48:51+00:00\" \/>\n\t\t<script type=\"application\/ld+json\" class=\"aioseo-schema\">\n\t\t\t{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/api-with-ruby-on-rails-useful-tricks\\\/#article\",\"name\":\"API with Ruby on Rails: useful tricks | Railsware Blog\",\"headline\":\"API with Ruby on Rails: useful tricks\",\"author\":{\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/author\\\/innokenty-mihailov\\\/#author\"},\"publisher\":{\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/#organization\"},\"image\":{\"@type\":\"ImageObject\",\"url\":\"https:\\\/\\\/railsware.com\\\/blog\\\/wp-content\\\/uploads\\\/2013\\\/04\\\/API-with-Ruby.png\",\"width\":360,\"height\":360,\"caption\":\"API with Ruby on Rails\"},\"datePublished\":\"2013-04-08T12:02:55+03:00\",\"dateModified\":\"2026-06-16T15:48:51+03:00\",\"inLanguage\":\"en-US\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/api-with-ruby-on-rails-useful-tricks\\\/#webpage\"},\"isPartOf\":{\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/api-with-ruby-on-rails-useful-tricks\\\/#webpage\"},\"articleSection\":\"Engineering, Innokenty Mihailov\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/api-with-ruby-on-rails-useful-tricks\\\/#breadcrumblist\",\"itemListElement\":[{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/railsware.com\\\/blog#listItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/railsware.com\\\/blog\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/category\\\/development\\\/#listItem\",\"name\":\"Engineering\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/category\\\/development\\\/#listItem\",\"position\":2,\"name\":\"Engineering\",\"item\":\"https:\\\/\\\/railsware.com\\\/blog\\\/category\\\/development\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/api-with-ruby-on-rails-useful-tricks\\\/#listItem\",\"name\":\"API with Ruby on Rails: useful tricks\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/railsware.com\\\/blog#listItem\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/api-with-ruby-on-rails-useful-tricks\\\/#listItem\",\"position\":3,\"name\":\"API with Ruby on Rails: useful tricks\",\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/category\\\/development\\\/#listItem\",\"name\":\"Engineering\"}}]},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/#organization\",\"description\":\"Blog on Engineering, Product Management, Transparency, Culture and many more...\",\"url\":\"https:\\\/\\\/railsware.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"url\":\"https:\\\/\\\/railsware.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/11\\\/Logo-circle.png\",\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/api-with-ruby-on-rails-useful-tricks\\\/#organizationLogo\",\"width\":3137,\"height\":1054,\"caption\":\"Railsware logo\"},\"image\":{\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/api-with-ruby-on-rails-useful-tricks\\\/#organizationLogo\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/author\\\/innokenty-mihailov\\\/#author\",\"url\":\"https:\\\/\\\/railsware.com\\\/blog\\\/author\\\/innokenty-mihailov\\\/\",\"name\":\"Innokenty Mihailov\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/api-with-ruby-on-rails-useful-tricks\\\/#authorImage\",\"url\":\"https:\\\/\\\/railsware.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/06\\\/author-image-default-96x96.jpg\",\"width\":96,\"height\":96,\"caption\":\"Innokenty Mihailov\"}},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/api-with-ruby-on-rails-useful-tricks\\\/#webpage\",\"url\":\"https:\\\/\\\/railsware.com\\\/blog\\\/api-with-ruby-on-rails-useful-tricks\\\/\",\"name\":\"API with Ruby on Rails: useful tricks | Railsware Blog\",\"description\":\"This article is about gotchas you should be aware of while building your API with Ruby on Rails.\",\"inLanguage\":\"en-US\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/#website\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/api-with-ruby-on-rails-useful-tricks\\\/#breadcrumblist\"},\"author\":{\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/author\\\/innokenty-mihailov\\\/#author\"},\"creator\":{\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/author\\\/innokenty-mihailov\\\/#author\"},\"image\":{\"@type\":\"ImageObject\",\"url\":\"https:\\\/\\\/railsware.com\\\/blog\\\/wp-content\\\/uploads\\\/2013\\\/04\\\/API-with-Ruby.png\",\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/api-with-ruby-on-rails-useful-tricks\\\/#mainImage\",\"width\":360,\"height\":360,\"caption\":\"API with Ruby on Rails\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/api-with-ruby-on-rails-useful-tricks\\\/#mainImage\"},\"datePublished\":\"2013-04-08T12:02:55+03:00\",\"dateModified\":\"2026-06-16T15:48:51+03:00\"},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/railsware.com\\\/blog\\\/\",\"description\":\"Blog on Engineering, Product Management, Transparency, Culture and many more...\",\"inLanguage\":\"en-US\",\"publisher\":{\"@id\":\"https:\\\/\\\/railsware.com\\\/blog\\\/#organization\"}}]}\n\t\t<\/script>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"API with Ruby on Rails: useful tricks | Railsware Blog","description":"This article is about gotchas you should be aware of while building your API with Ruby on Rails.","canonical_url":"https:\/\/railsware.com\/blog\/api-with-ruby-on-rails-useful-tricks\/","robots":"max-snippet:-1, max-image-preview:large, max-video-preview:-1","keywords":"","webmasterTools":{"miscellaneous":""},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/railsware.com\/blog\/api-with-ruby-on-rails-useful-tricks\/#article","name":"API with Ruby on Rails: useful tricks | Railsware Blog","headline":"API with Ruby on Rails: useful tricks","author":{"@id":"https:\/\/railsware.com\/blog\/author\/innokenty-mihailov\/#author"},"publisher":{"@id":"https:\/\/railsware.com\/blog\/#organization"},"image":{"@type":"ImageObject","url":"https:\/\/railsware.com\/blog\/wp-content\/uploads\/2013\/04\/API-with-Ruby.png","width":360,"height":360,"caption":"API with Ruby on Rails"},"datePublished":"2013-04-08T12:02:55+03:00","dateModified":"2026-06-16T15:48:51+03:00","inLanguage":"en-US","mainEntityOfPage":{"@id":"https:\/\/railsware.com\/blog\/api-with-ruby-on-rails-useful-tricks\/#webpage"},"isPartOf":{"@id":"https:\/\/railsware.com\/blog\/api-with-ruby-on-rails-useful-tricks\/#webpage"},"articleSection":"Engineering, Innokenty Mihailov"},{"@type":"BreadcrumbList","@id":"https:\/\/railsware.com\/blog\/api-with-ruby-on-rails-useful-tricks\/#breadcrumblist","itemListElement":[{"@type":"ListItem","@id":"https:\/\/railsware.com\/blog#listItem","position":1,"name":"Home","item":"https:\/\/railsware.com\/blog","nextItem":{"@type":"ListItem","@id":"https:\/\/railsware.com\/blog\/category\/development\/#listItem","name":"Engineering"}},{"@type":"ListItem","@id":"https:\/\/railsware.com\/blog\/category\/development\/#listItem","position":2,"name":"Engineering","item":"https:\/\/railsware.com\/blog\/category\/development\/","nextItem":{"@type":"ListItem","@id":"https:\/\/railsware.com\/blog\/api-with-ruby-on-rails-useful-tricks\/#listItem","name":"API with Ruby on Rails: useful tricks"},"previousItem":{"@type":"ListItem","@id":"https:\/\/railsware.com\/blog#listItem","name":"Home"}},{"@type":"ListItem","@id":"https:\/\/railsware.com\/blog\/api-with-ruby-on-rails-useful-tricks\/#listItem","position":3,"name":"API with Ruby on Rails: useful tricks","previousItem":{"@type":"ListItem","@id":"https:\/\/railsware.com\/blog\/category\/development\/#listItem","name":"Engineering"}}]},{"@type":"Organization","@id":"https:\/\/railsware.com\/blog\/#organization","description":"Blog on Engineering, Product Management, Transparency, Culture and many more...","url":"https:\/\/railsware.com\/blog\/","logo":{"@type":"ImageObject","url":"https:\/\/railsware.com\/blog\/wp-content\/uploads\/2020\/11\/Logo-circle.png","@id":"https:\/\/railsware.com\/blog\/api-with-ruby-on-rails-useful-tricks\/#organizationLogo","width":3137,"height":1054,"caption":"Railsware logo"},"image":{"@id":"https:\/\/railsware.com\/blog\/api-with-ruby-on-rails-useful-tricks\/#organizationLogo"}},{"@type":"Person","@id":"https:\/\/railsware.com\/blog\/author\/innokenty-mihailov\/#author","url":"https:\/\/railsware.com\/blog\/author\/innokenty-mihailov\/","name":"Innokenty Mihailov","image":{"@type":"ImageObject","@id":"https:\/\/railsware.com\/blog\/api-with-ruby-on-rails-useful-tricks\/#authorImage","url":"https:\/\/railsware.com\/blog\/wp-content\/uploads\/2021\/06\/author-image-default-96x96.jpg","width":96,"height":96,"caption":"Innokenty Mihailov"}},{"@type":"WebPage","@id":"https:\/\/railsware.com\/blog\/api-with-ruby-on-rails-useful-tricks\/#webpage","url":"https:\/\/railsware.com\/blog\/api-with-ruby-on-rails-useful-tricks\/","name":"API with Ruby on Rails: useful tricks | Railsware Blog","description":"This article is about gotchas you should be aware of while building your API with Ruby on Rails.","inLanguage":"en-US","isPartOf":{"@id":"https:\/\/railsware.com\/blog\/#website"},"breadcrumb":{"@id":"https:\/\/railsware.com\/blog\/api-with-ruby-on-rails-useful-tricks\/#breadcrumblist"},"author":{"@id":"https:\/\/railsware.com\/blog\/author\/innokenty-mihailov\/#author"},"creator":{"@id":"https:\/\/railsware.com\/blog\/author\/innokenty-mihailov\/#author"},"image":{"@type":"ImageObject","url":"https:\/\/railsware.com\/blog\/wp-content\/uploads\/2013\/04\/API-with-Ruby.png","@id":"https:\/\/railsware.com\/blog\/api-with-ruby-on-rails-useful-tricks\/#mainImage","width":360,"height":360,"caption":"API with Ruby on Rails"},"primaryImageOfPage":{"@id":"https:\/\/railsware.com\/blog\/api-with-ruby-on-rails-useful-tricks\/#mainImage"},"datePublished":"2013-04-08T12:02:55+03:00","dateModified":"2026-06-16T15:48:51+03:00"},{"@type":"WebSite","@id":"https:\/\/railsware.com\/blog\/#website","url":"https:\/\/railsware.com\/blog\/","description":"Blog on Engineering, Product Management, Transparency, Culture and many more...","inLanguage":"en-US","publisher":{"@id":"https:\/\/railsware.com\/blog\/#organization"}}]},"og:locale":"en_US","og:site_name":"| Blog on Engineering, Product Management, Transparency, Culture and many more...","og:type":"article","og:title":"API with Ruby on Rails: useful tricks | Railsware Blog","og:description":"This article is about gotchas you should be aware of while building your API with Ruby on Rails.","og:url":"https:\/\/railsware.com\/blog\/api-with-ruby-on-rails-useful-tricks\/","og:image":"https:\/\/railsware.com\/blog\/wp-content\/uploads\/2013\/04\/API-with-Ruby.png","og:image:secure_url":"https:\/\/railsware.com\/blog\/wp-content\/uploads\/2013\/04\/API-with-Ruby.png","og:image:width":360,"og:image:height":360,"article:published_time":"2013-04-08T09:02:55+00:00","article:modified_time":"2026-06-16T12:48:51+00:00"},"aioseo_meta_data":{"post_id":"4508","title":"API with Ruby on Rails: useful tricks | Railsware Blog","description":"This article is about gotchas you should be aware of while building your API with Ruby on Rails.","keywords":null,"keyphrases":{"focus":{"keyphrase":"","score":0,"analysis":{"keyphraseInTitle":{"score":0,"maxScore":9,"error":1}}},"additional":[]},"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":"","og_custom_url":null,"og_article_section":null,"og_article_tags":null,"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":[],"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"Article","isEnabled":true},"graphs":[]},"schema_type":"none","schema_type_options":"{\"article\":{\"articleType\":\"BlogPosting\"},\"course\":{\"name\":\"\",\"description\":\"\",\"provider\":\"\"},\"faq\":{\"pages\":[]},\"product\":{\"reviews\":[]},\"recipe\":{\"ingredients\":[],\"instructions\":[],\"keywords\":[]},\"software\":{\"reviews\":[],\"operatingSystems\":[]},\"webPage\":{\"webPageType\":\"WebPage\"},\"book\":[],\"event\":[],\"jobPosting\":[],\"music\":[],\"person\":[],\"restaurant\":[],\"service\":[],\"video\":[]}","pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":"-1","robots_max_videopreview":"-1","robots_max_imagepreview":"large","priority":null,"frequency":"default","location":null,"local_seo":null,"breadcrumb_settings":null,"limit_modified_date":false,"ai":{"faqs":[],"keyPoints":[],"schemas":[],"titles":[],"descriptions":[],"socialPosts":{"email":[],"linkedin":[],"twitter":[],"facebook":[],"instagram":[]}},"created":"2021-01-04 12:44:28","updated":"2026-06-16 13:47:49","seo_analyzer_scan_date":null},"aioseo_breadcrumb":"<div class=\"aioseo-breadcrumbs\"><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/railsware.com\/blog\" title=\"Home\">Home<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/railsware.com\/blog\/category\/development\/\" title=\"Engineering\">Engineering<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\tAPI with Ruby on Rails: useful tricks\n\t\t<\/span><\/div>","aioseo_breadcrumb_json":[{"label":"Home","link":"https:\/\/railsware.com\/blog"},{"label":"Engineering","link":"https:\/\/railsware.com\/blog\/category\/development\/"},{"label":"API with Ruby on Rails: useful tricks","link":"https:\/\/railsware.com\/blog\/api-with-ruby-on-rails-useful-tricks\/"}],"categories_data":[{"name":"Engineering","link":"https:\/\/railsware.com\/blog?category=development"}],"post_thumbnails":"https:\/\/railsware.com\/blog\/wp-content\/uploads\/2013\/04\/API-with-Ruby.png","article_background":"#f1f5fd","amp_enabled":true,"_links":{"self":[{"href":"https:\/\/railsware.com\/blog\/wp-json\/wp\/v2\/posts\/4508","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/railsware.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/railsware.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/railsware.com\/blog\/wp-json\/wp\/v2\/users\/34"}],"replies":[{"embeddable":true,"href":"https:\/\/railsware.com\/blog\/wp-json\/wp\/v2\/comments?post=4508"}],"version-history":[{"count":36,"href":"https:\/\/railsware.com\/blog\/wp-json\/wp\/v2\/posts\/4508\/revisions"}],"predecessor-version":[{"id":19089,"href":"https:\/\/railsware.com\/blog\/wp-json\/wp\/v2\/posts\/4508\/revisions\/19089"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/railsware.com\/blog\/wp-json\/wp\/v2\/media\/9484"}],"wp:attachment":[{"href":"https:\/\/railsware.com\/blog\/wp-json\/wp\/v2\/media?parent=4508"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/railsware.com\/blog\/wp-json\/wp\/v2\/categories?post=4508"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/railsware.com\/blog\/wp-json\/wp\/v2\/tags?post=4508"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/railsware.com\/blog\/wp-json\/wp\/v2\/coauthors?post=4508"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}