Hackernoon logoCRUD and the 7 RESTful actions by@stefan_dili

CRUD and the 7 RESTful actions

Author profile picture

@stefan_diliStefan Dili

When I’m learning something new I like to talk to myself about it until I feel I understand it. You can feel when you’re just hiding behind the fact that no one else is questioning you, and you’re really just kind of lying to yourself. “Yeah yeah, REST, CRUD, awfully simple…”
This was one of those times when I was trying to grasp a concept, which actually is simple, but only when I talk it out a bit.
The thing that confused me and probably a lot of other folks, is that CRUD is 4 distinct operations and there are seven RESTful actions.So we’ll be going through them all here.
To understand them better, divide them by whether your consuming data, or feeding it. Read is consuming, all the others are feeding.
Create is self explanatory. Creating something new. A post or a user account on a social network, an item for sale on an online shop, an ad for an upcoming seminar…
Read is just displaying anything, and it’s the operation that holds the most RESTful actions.
Update, well… You guessed it. Change some data that’s already present.
Delete. This one needs a whole article for itself… JK
So Create, Read, Update, Delete. Pretty simple right?
Now let’s list the RESTful actions:

1. Create
2. Index
3. New
4. Show
5. Edit
6. Update
7. Delete
I’ve listed them in CRUD order, and R holds Index, New, Show, and Edit. It's all reading, but different things.
Let’s go through the flow now.
You enter a social network website. You see create account and some sort of form to fill out, usually name, email etc. This is action #3 new. It’s R of CRUD, displaying to you the page where you make a new X, in this case a user profile. The same would be true if you were adding an item on a marketplace, and it would look almost the same.
So, you fill out the form and click on create account, submitting the info you entered. Action #1, create.
Now your account is stored somewhere in the database, and you are redirected you to your profile page. This is action #4 show. It reads a specific instance of a database entry, in this case your profile.
And now, you’re looking at your awesome profile picture, checking your info and realize you typed Narc instead of Marc and that's not very good!
You look around and see an option to edit, most probably a little pencil nowadays. You click on it and again the page changes, and a form is shown prefilled with your info which you can now edit. Action #5, reading the edit page!
You clean your case and click submit and voila, you’ve fed the browser again with some info and performed action #6 update.
Phew! Now that that’s fixed you want to find which of your friends are already there so you find the appropriate button which gives you action #2 index. A list of database objects that fit the query (if their filters and algorithms are up to par) appears.
At this moment, you realize it’s Sunday 2 am, you’re moderately drunk (explains why you misspelled your name) and consequently made a profile on the wrong social network!
Thankfully, you navigate to your dashboard and click the button that says (action #7) delete (profile).
A little bit ashamed of this whole situation, you realize it’s probably best you go to bed, but at least you’re able to sleep well and with a smile because at least you learn some CRUD :)

Tags

The Noonification banner

Subscribe to get your daily round-up of top tech stories!