Skip to content

Instantly share code, notes, and snippets.

@ThinhPhan
Created April 5, 2019 16:19
Show Gist options
  • Save ThinhPhan/71c4df21774a7a11563b593e027a980a to your computer and use it in GitHub Desktop.
Save ThinhPhan/71c4df21774a7a11563b593e027a980a to your computer and use it in GitHub Desktop.

Resourceful Routing for CRUD Operations in Web Applications

Note: The RESTful routes also apply to RESTful APIs, however JSON is returned to the client vs. HTML

RESTful Routes:

HTTP Verb Path (endpoint) controller#action View to Render
or Redirect
Purpose
GET /posts posts#index index List all posts
GET /posts/:id posts#show show Show a single post
POST /posts posts#create redirect Create a new post
PUT /posts/:id posts#update redirect Update a post
DELETE /posts/:id posts#destroy redirect Delete a post

Useful Non-RESTful Routes:

HTTP Verb Path (endpoint) controller#action Default View
or Redirect
Purpose
GET /posts/new posts#new new Provide form for
submitting new post
to the create action
GET /posts/:id/edit posts#edit edit Provide form for
editing a post
and sending to the
update action
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment