[英]ROR - Extract ID from HTTP response location
I have a REST call to Java services which does a POST to the path 我有一个对Java服务的REST调用,该调用对路径进行了POST
localhost:8080/api/xyz
and returns the response. 并返回响应。 The response of course has the response.header['location'] with a correct location with ID
当然,响应中包含带有正确位置ID的response.header ['location']
'xyz/{id}'
For my further steps in the method I just need to extract ONLY the 'id' part from the 'location'. 对于该方法的后续步骤,我只需要从“位置”中提取“ id”部分即可。 Right now this is what I am doing,
现在这就是我在做的
(response.header['location'].split('/'))[1]
Is there a better way to get around this? 有更好的方法来解决这个问题吗?
One of the solution provided by rails: rails提供的解决方案之一:
# routes.rb
get '/api/:id'
# view or controller
params[:id]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.