#49 Rails API Basics


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.
rails api routes 5:28


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

  # Same as doing:
  # constraints subdomain: 'api' do
  #   namespace :api, path: '/' do
  #     resources :users
  #   end
  # end
controllers/api/users_controller.rbmodule Api
  class UsersController < ApplicationController
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
sadiqmmm said over 3 years ago on Rails API Basics :

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..

jomarbarnobal said about 3 years ago on Rails API Basics :

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

kobaltz PRO said about 3 years ago on Rails API Basics :

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

jomarbarnobal said about 3 years ago on Rails API Basics :

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