Sha256: 5c69ceba52624ee8c2698763a4643f7d61e89b4f06fb6417999fc9c455a4f8dc

Contents?: true

Size: 1.17 KB

Versions: 4

Compression:

Stored size: 1.17 KB

Contents

# It will works with respond_with.
# Your action should looks like any other one: A model with a method call. =D
class UserController < ApplicationController
  # It will hit http://api.example.com/users with a get request
  def index
    @users = User.collection
    respond_with(@users)
  end

  # It will initialize a new object based on the attribute accessors
  def new
    @user = User.new
    respond_with(@user)
  end

  # It will hit http://api.example.com/users with a post request
  def create
    @user = User.post(:user => params[:user])
    respond_with(@user)
  end

  # It will hit http://api.example.com/users/1 with a get request
  def edit
    @user = User.get(params[:id])
    respond_with(@user)
  end

  # It will hit http://api.example.com/users/1 with a patch request
  def update
    @user = User.patch(params[:id], { :user => params[:user] })
    respond_with(@user)
  end

  # It will hit http://api.example.com/users/1 with a get request
  def show
    @user = User.get(params[:id])
    respond_with(@user)
  end

  # It will hit http://api.example.com/users/1 with a delete request
  def delete
    @user = User.delete(params[:id])
    respond_with(@user)
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
api-client-2.3.0 examples/controllers/user_controller.rb
api-client-2.2.0 examples/controllers/user_controller.rb
api-client-2.1.0 examples/controllers/user_controller.rb
api-client-2.0.3 examples/controllers/user_controller.rb