我正在學習如何使用RoR編寫一個restful API並且有一個與它相關的問題。所以,我會解釋我與代碼一起做了什麼。帶欄杆的Restful api
這是我的控制器看起來像:
class EmployeesController < ApplicationController
require 'rest_client'
def index
uri = "localhost:3000/employees"
rest_resource = RestClient::Resource.new(uri)
users = rest_resource.get # will get back you all the detail in json format, but it will we wraped as string, so we will parse it in the next step.
@users = JSON.parse(users, :symbolize_names => true) # convert the return data into array
@users.each do |u|
logger.info(u.id)
end
# return based on the format type
respond_to do |format|
format.json {render json: @users}
format.xml {render xml: @users}
format.html
end
end
末
在我的Gemfile,我已經包含了其他的客戶端也是如此。
gem 'rest-client'
我的路線是: 根的員工#指數「 資源, '僱員'
希望一切都很好至今。
現在,當我送:
- >捲曲請求 'http://localhost:3000/employees',它卡住。
- >在'http://localhost:3000/'獲取請求(通過在瀏覽器中輸入),它也陷在這裏。
我失蹤的是什麼?
'/ employess'命中EmployeesController#索引嗎? – Santhosh
@Santhosh,是的,它擊中了那個。 –
是不是一個無限循環? – Santhosh