How to remove PUT method from phx.routes?

Phoenix version - 1.6.6
My phoenix routes:

 swagger_ui_path  GET    /getmsg/swaggerui         OpenApiSpex.Plug.SwaggerUI [path: "/getmsg/api/openapi"]
render_spec_path  GET    /getmsg/api/openapi       OpenApiSpex.Plug.RenderSpec []
 auth_token_path  POST   /getmsg/api/auth-tokens   GetmsgApi.AuthTokenController :create
    message_path  GET    /getmsg/api/messages      GetmsgApi.MessageController :index
    message_path  GET    /getmsg/api/messages/:id  GetmsgApi.MessageController :show
    message_path  PATCH  /getmsg/api/messages/:id  GetmsgApi.MessageController :update
                  PUT    /getmsg/api/messages/:id  GetmsgApi.MessageController :update

How to remove PUT method? I don’t need it.

Did this come up automatically using resources "/getmsg/api/messages", MessageController ? If so the PUT verb was generated automatically. You can avoid this by excluding the :update routes in the controller with resources "/getmsg/api/messages", MessageController, except: [:update] and then creating another route with patch "/getmsg/api/messages", MessageController, :update. If you’re not getting that by using resources then we’d probably need to take a look at the relevant part of your router.

3 Likes

Why there is no Router Helpers for :update with id?

message_path(conn_or_endpoint, :index, params \\ [])
message_path(conn_or_endpoint, :show, id, params \\ [])
message_path(conn_or_endpoint, :update, params \\ [])

Missing message_path(conn_or_endpoint, :update, id, params \\ [])


Can’t use message_path(conn, :update, msg_id) anymore. I need this in my tests.

iex(9)> GetmsgApi.Router.Helpers.message_path(MyEndpoint, :update, :some_id)
** (ArgumentError) GetmsgApi.Router.Helpers.message_path/3 called with invalid params.
The last argument to this function should be a keyword list or a map.
For example:

    message_path(conn, :update, page: 5, per_page: 10)

It is possible you have called this function without defining the proper
number of path segments in your router.

With :show all is fine

iex(10)> GetmsgApi.Router.Helpers.message_path(MyEndpoint, :show, :some_id)
"/getmsg/api/messages/some_id"

Routers:

 swagger_ui_path  GET    /getmsg/swaggerui         OpenApiSpex.Plug.SwaggerUI [path: "/getmsg/api/openapi"]
render_spec_path  GET    /getmsg/api/openapi       OpenApiSpex.Plug.RenderSpec []
 auth_token_path  POST   /getmsg/api/auth-tokens   GetmsgApi.AuthTokenController :create
    message_path  GET    /getmsg/api/messages      GetmsgApi.MessageController :index
    message_path  GET    /getmsg/api/messages/:id  GetmsgApi.MessageController :show
    message_path  PATCH  /getmsg/api/messages      GetmsgApi.MessageController :update

router.ex:

scope "/api", GetmsgApi do
  pipe_through [:api, :authenticate_user]
  resources "/messages", MessageController, except: [:new, :edit, :create, :delete, :update]
  patch "/messages", MessageController, :update
end

This needs to be

patch "/getmsg/api/messages/:id", MessageController, :update
2 Likes

Thank u, just find this in Phoenix docs too. It was so stupid