Skip to content

Instantly share code, notes, and snippets.

@ursulacj
Created February 12, 2019 18:04
Show Gist options
  • Save ursulacj/bbef65d894657b49d47b4cf86d8efa17 to your computer and use it in GitHub Desktop.
Save ursulacj/bbef65d894657b49d47b4cf86d8efa17 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