1
현재 내 웹 사이트의 API에 대한 문서를 작성하고 있습니다.API 문서의 레일 경로
경로를 작성하는 가장 좋은 방법은 확실하지 않습니다.
https://dev.twitter.com/docs/api
https://dev.twitter.com/docs/api/1/get/statuses/show/:id
https://dev.twitter.com/docs/api/1/post/statuses/retweet/:id
그것은 것 같은 뭔가 :이 부분에 대한 경로를 작성하는 방법에
namespace :docs do
resources :api do
# and then... not sure
end
end
확실하지 나는 트위터가 좋은 일을하고 나는 그들의 URL 구조를 복사 할 생각 : /get/statuses/show/:id
.
맞춤 경로를 만들어야하나요?
match "/:verb/:resource/:action/:params" => "api#resource"
더 좋은 방법이 있습니까?
내가 함께 결국 무엇,
Ibarcraft::Application.routes.draw do
def api_versions; [:v1] end
def api_verbs; [ :index, :show ] end
constraints subdomain: "api" do
scope module: "api", as: "api" do
versions = api_versions
versions.each do |version|
namespace version, defaults: { format: "json" } do
# all my routes
resources :barcrafts, only: api_verbs do
collection do
get :search
end
scope module: "barcraft" do
resources :users, only: [:index]
end
end
# and more...
end
end
match 'v:api/*path', to: redirect { |params, request| "/#{versions.last}/#{params[:path]}" + (params[:format] ? ".#{params[:format]}" : "") }
match '*path', to: redirect { |params, request| "/#{versions.last}/#{params[:path]}" + (params[:format] ? ".#{params[:format]}" : "") }
end
end
end
같은 것을 사용, 컨트롤러의 액션 이름을 위해 예약되어
그러나 참고. – Robin