- Read Tutorial
So what's REST?
This is a term that gets thrown around a lot, especially when it comes to API development, so let's begin with what is REST?
REST is an acronym for an application design pattern. The breakdown is below:
Representational
State
Transfer
Clear as mud right? Elkstein says:
It relies on a stateless, client-server, cacheable communications protocol -- and in virtually all cases, the HTTP protocol is used. REST is an architecture style for designing networked applications.
That's still too complex. Let's get even more high level: REST is an easy way to name CRUD routes, that's it (here is a CRUD explanation if that's a little fuzzy). Taking an easy example, let's say that we have a Post
object, let's see what routes are needed for the following actions:
Create a Post
/posts/new
Edit a Post
posts/1/edit
Show a Post
posts/1
That's a very basic example. Rails follows RESTful principles very closely, let's look at each of the routes you would typically use:
This includes each of the actions you'd need to Create, Read, Update, and Delete a record from the database.
So why is REST important?
RESTful principles are mainly important because they give standardized guide for how we name routes, both for applications and APIs. Technically with a Rails application you could create routes that don't follow RESTful principles, however this would be counterintuitive since you want your APIs to be easy to follow for other developers (and yourself). With that in mind throughout this course we'll be following best practices and using RESTful based routes for our API development.