gpt4 book ai didi

elixir - Phoenix 框架中的动态路由

转载 作者:行者123 更新时间:2023-12-04 19:38:14 26 4
gpt4 key购买 nike

用户访问以下路由:www.example.com/api/users/x ,其中 x 是可变的。

如何获取 x 并创建具有动态响应的路由?

自动翻译。

最佳答案

在您的 router.ex 中,您需要编写如下内容 -

get "/api/users/:x", SomeController, :actionName

现在在您的 Controller 中,您需要使用模式匹配从 _params 中获取 x 的值,即:
def actionName(conn,  %{"x" => x}) do
# now x is available here
end

更多详情, http://www.phoenixframework.org/docs/controllers

关于elixir - Phoenix 框架中的动态路由,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39186571/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com