What is CRUD?
CRUD is an acronym for Create, Read, Update, and Delete, the four fundamental operations of data storage. Computer scientists use CRUD as a measure of an application’s completion state. If an application can’t perform CRUD operations, it is incomplete.
CRUD Operations
- Create - the operation creates a new record in the database.
- Read - the operation reads information from a record in the database.
- Update - the operation changes a record’s information in the database.
- Delete - the operation removes a record from the database.
CRUD Example
Let’s say we’re building a web business that sells socks. When a customer visits our website, we want to provide up-to-date inventory information.
- Create- We’re adding green socks to our inventory, so we need a function that creates a new record. The new record contains values for sock size and the number of socks in inventory.
- Read- When a customer views our new green socks, a function reads the sock record, so the customer knows if it’s available.
- Update- The customer loves the green socks. Great! When they buy the socks, a function updates the sock record. We might also use this event to trigger some webhooks.
- Delete- Green dye has gotten expensive, so we’re no longer selling green socks. Delete removes the record from the database.
What’s the difference between CRUD and REST?
What about CRUD in the age of microservices, where applications exist on multiple containers across multiple databases? Is it outdated? Not at all! Perhaps you’ve heard of REST in your programming journey. The relationship between REST and CRUD can be confusing, but we’re here to help.
REST
The REST (REpresentational State Transfer) protocol was designed to standardize HTTP communication between clients and servers. REST is a system of rules and connectors all services must follow and use. If you’ve ever had to order a special dongle for that one piece of hardware without a USB connector, you understand the problem that REST solves.
The difference between CRUD and REST
So, if we’re manipulating data on a database with REST, it’s the same as CRUD, right? Not quite.
REST refers to manipulating data through HTTP commands, and an ideology for how to streamline the relationship between the data that a user is manipulating on screen and the information that is saved on the server. A programmer can create a REST API that handles basic CRUD functions, but building a CRUD application in no way insinuates the use of RESTful programming.
It’s easy to confuse CRUD and REST operations because their operations are roughly analogous to each other, but if you remember that REST is a set of standards, and CRUD is a set of functions, you’ll be on your way to a deeper understanding.