Rails API Basics

#49 Rails API Basics
10/2/2016

Summary

A brief introduction on Rails API. Learn how to create an API application and setup the routes. This episode is paving the way for more in depth looks into Rails API.
15
rails api routes

Summary

Consolerails new APP_NAME --api
Consolerake routes
   Prefix Verb   URI Pattern          Controller#Action
api_users GET    /users(.:format)     api/users#index {:subdomain=>"api"}
          POST   /users(.:format)     api/users#create {:subdomain=>"api"}
 api_user GET    /users/:id(.:format) api/users#show {:subdomain=>"api"}
          PATCH  /users/:id(.:format) api/users#update {:subdomain=>"api"}
          PUT    /users/:id(.:format) api/users#update {:subdomain=>"api"}
          DELETE /users/:id(.:format) api/users#destroy {:subdomain=>"api"}
routes.rbRails.application.routes.draw do
  namespace :api, path: '/', constraints: { subdomain: 'api' } do
    resources :users
  end

  # Same as doing:
  # constraints subdomain: 'api' do
  #   namespace :api, path: '/' do
  #     resources :users
  #   end
  # end
end
controllers/api/users_controller.rbmodule Api
  class UsersController < ApplicationController
   ...
  end
end
config/application.rbmodule ApiDemo
  class Application < Rails::Application
    # Only loads a smaller set of middleware suitable for API only apps.
    # Middleware like session, flash, cookies can be added back manually.
    # Skip views, helpers and assets when generating a new resource.
    config.api_only = true
  end
end
672989?v=3&s=64
sadiqmmm said 8 months ago:

Thank you bro for really amazing video on RAILS API.

Looking for more videos on RAILS API. As you said RAILS API with devise and IOS App.

Waiting for the next videos..

12394146?v=3&s=64
jomarbarnobal said 5 months ago:

Good day sir, How did you set-up the devise? , is it a normal install in rails api ? by the way thanks and its awesome tutorial

635114?v=3&s=64
kobaltz said 5 months ago:

It was just a normal "default" install as what can be found in the README; customizations with controllers, models, config, etc. were not done. 

12394146?v=3&s=64
jomarbarnobal said 5 months ago:

Thanks for your reply sir! I kinda confuse coz there's already a devise installed and you create an another controller for user

Login to Comment