Dynamic routes in Phoenix Framework

Cláudio Júlio

The user accesses the following route: www.example.com/api/users/x, where x is variable.

How to get x and create routes with dynamic responses?

Automatically translated.

Tahmina Khatoon

In your router.ex you need to write something like following -

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

Now in your controller, you need to use patten matching to get the value of x from _params, ie:

def actionName(conn,  %{"x" => x}) do
    # now x is available here
end

For more details, http://www.phoenixframework.org/docs/controllers

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related