将 /api/v1/ url 方案添加到 Rails 应用程序

发布于 2024-12-25 16:29:07 字数 245 浏览 4 评论 0原文

我正在规划一个主要通过 API 通过客户端应用程序公开的 Web 应用程序。我之前使用过 Rails,所以我将使用它来创建后端。

在规划 API 时,我在 url 方案中添加了一层,如下所示:

http://websitename .com/api/v1/...

将其添加到我的应用程序中的最佳方法是什么?

I'm planning a web app that is exposed primarily through a client application through an API. I've worked with rails before so am going to use this to create the back-end.

Whilst planning the API, I've added in a layer to the url scheme that is as follows:

http://websitename.com/api/v1/...

What is the best way for me to add this to my application?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

荒路情人 2025-01-01 16:29:07

尝试一下葡萄。它是一个小宝石,可以帮助您设计和编码此类内容。

Give a try to grape. It's a little gem that will help you to design and code this kind of stuff.

波浪屿的海角声 2025-01-01 16:29:07

我没有像上面提到的那样使用 Grape,但你总是可以在你的路由文件中使用一个范围。

scope '/api' do
    match v1/something_here => controller_name#method_name, :as=>'desired_name'
end

或者

scope '/api/v1'

如果你需要的话。

或者

scope :module => 'api', :as => 'api' do
    scope '/v1' do

    end
end

I have not used Grape as mentioned above but you can always go with a scope in your routes file.

scope '/api' do
    match v1/something_here => controller_name#method_name, :as=>'desired_name'
end

OR

scope '/api/v1'

if you need it.

OR

scope :module => 'api', :as => 'api' do
    scope '/v1' do

    end
end
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文