What are REST, Routes, CRUD?
Representation State Transfer or REST is a pattern/convention for defining our routes. Routes are the code that listens and receives requests then figures out what to send back. CRUD stands for Create, Read, Update, and Delete. These are the 4 basic functions we have when building an API.
So why do we want any of this? Mostly it’s just about keeping things simple and repeatable when building apps. By following a convention we don’t have to reinvent the wheel every time we make an app and other developers will quickly figure out what’s going on.
The Magnificent 7
REST is made up of 7 standard routes:
Name | URL | HTTP Verb | Description |
Index | /teams | GET | Displays a list of all teams |
New | /teams/new | GET | Displays a new team form |
Create | /teams | POST | Adds new team to the database then redirects |
Show | /teams/:id | GET | Shows a particular team |
Edit | /teams/edit/:id | GET | Shows an edit form for a particular team |
Update | /teams/:id | PUT | Updates a particular team in the database then redirects |
Destroy | /teams/:id | DELETE | Removes a particular team from the database then redirects |