我正在学习如何使用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