** (Phoenix.Router.NoRouteError) no route found for PUT /books (LibraryApiWeb.Router) RESOLVED!

I am currently creating an API for an author-books type of app.
I already created the Library functions and the controllers and view for books but upon trying to submit a PUT data to http://localhost:3000/books I am encountering the following error response:

# Phoenix.Router.NoRouteError at PUT /books


    ** (Phoenix.Router.NoRouteError) no route found for PUT /books (LibraryApiWeb.Router)
        (library_api) lib/library_api_web/router.ex:1: LibraryApiWeb.Router.__match_route__/4
        (library_api) lib/phoenix/router.ex:304: LibraryApiWeb.Router.call/2
        (library_api) lib/library_api_web/endpoint.ex:1: LibraryApiWeb.Endpoint.plug_builder_call/2
        (library_api) lib/plug/debugger.ex:122: LibraryApiWeb.Endpoint."call (overridable 3)"/2
        (library_api) lib/library_api_web/endpoint.ex:1: LibraryApiWeb.Endpoint.call/2
        (phoenix) lib/phoenix/endpoint/cowboy2_handler.ex:33: Phoenix.Endpoint.Cowboy2Handler.init/2
        (cowboy) d:/@@@/@gbzapp/library_api/deps/cowboy/src/cowboy_handler.erl:41: :cowboy_handler.execute/2
        (cowboy) d:/@@@/@gbzapp/library_api/deps/cowboy/src/cowboy_stream_h.erl:296: :cowboy_stream_h.execute/3
        (cowboy) d:/@@@/@gbzapp/library_api/deps/cowboy/src/cowboy_stream_h.erl:274: :cowboy_stream_h.request_process/3
        (stdlib) proc_lib.erl:249: :proc_lib.init_p_do_apply/3

I have the proper routes entry:


  scope "/", LibraryApiWeb do
    pipe_through :api
    get "/", StatusController, :index

    resources "/authors", AuthorController, except: [:new, :edit]
    resources "/books", BookController, except: [:new, :edit]

Been trying to check what I could be missing but been on it for some hours already.
I am using phoenix 1.4.3.
Would be glad to hear your feedback. Thanks!

Run ‘mix phx.routes’ it will show which routes the ‘resources’ macro is generating.

I guess you want POST instead of PUT in this case.

I have the following output for mix phx.routes and it seems ok with PUT:

  book_path  GET     /books             LibraryApiWeb.BookController :index
  book_path  GET     /books/:id         LibraryApiWeb.BookController :show
  book_path  POST    /books             LibraryApiWeb.BookController :create
  book_path  PATCH   /books/:id         LibraryApiWeb.BookController :update
             PUT     /books/:id         LibraryApiWeb.BookController :update
  book_path  DELETE  /books/:id         LibraryApiWeb.BookController :delete

I am trying to do an edit so I am using PUT. My create is okay

But You did not supply the id… so the router has no match.

Also, are You sure for localhost:3000, it looks like a Rails address :slight_smile:


Yea! You are right!!!
Thanks so much!
Stupid things some newbies like me have to go thru haha!
Thanks again @kokolegorille & @kwando!

BTW You can mark any post has the solution (There is a button if You are the original poster) instead of updating the title :slight_smile:

I missed that @kokolegorille! Complied with :D.
Thanks for the info!

1 Like

Btw, for those following this, I failed to supply the id. The port 3000 was a customization I did

1 Like

This is a form example from Programming Phoenix. But You might get the same with a generator.

In your templates, You might find some forms with…

<%= form_for @changeset, @action, fn f -> %>

This @action is set in both new and edit, but with some difference.

In edit You might find…

<%= render "form.html", Map.put(assigns, :action, Routes.video_path(@conn, :update, @video)) %>

This is where You pass @video, which will contains the id.