CRUD
Create, Read, Update, Delete
- Pronunciation
- KRUD
In short
CRUD stands for create, read, update and delete, the four basic operations for working with stored data in databases, APIs and most business applications.
What is CRUD?
CRUD names the four things you can do with a stored record: create a new one, read existing ones, update one, and delete one. Nearly every application that stores data, from a to-do list to a banking system, is built around these operations, which is why simple data-management apps are often called CRUD apps.
In SQL, the four operations map to INSERT, SELECT, UPDATE, and DELETE. In a REST API, they usually map to HTTP methods on a resource URL: POST /tasks creates, GET /tasks/7 reads, PUT or PATCH /tasks/7 updates, and DELETE /tasks/7 deletes. ORMs and many web frameworks can generate CRUD code, admin screens, and API endpoints for a data model automatically, which saves a lot of repetitive work.
CRUD is like managing a paper address book: you write in a new contact, look someone up, cross out and correct a phone number, or tear out a page. Real applications wrap rules around each operation, such as validation before creating or updating, authorization checks on who may read or delete, and pagination when reading long lists. Many systems also avoid permanent deletes with a soft delete, which only marks a record as deleted, for example with a deleted_at timestamp, so it can be restored or audited later.
CRUD is often confused with REST. CRUD describes operations on data, while REST is an architectural style for designing APIs; a REST API often exposes CRUD operations, but REST also covers ideas such as statelessness and resource URLs, and many API actions, like 'send a password reset email' or 'approve an order', aren't CRUD at all. CRUD is also contrasted with CQRS, an architecture that separates the write side of an application from the read side into different models.
Key takeaways
- CRUD stands for create, read, update, and delete.
- In SQL, the operations are
INSERT,SELECT,UPDATE, andDELETE. - In REST APIs, they usually map to
POST,GET,PUTorPATCH, andDELETE. - Real CRUD features add validation, authorization, and pagination.
- CRUD describes operations on data; REST describes how an API is designed.
Example
-- Create
INSERT INTO tasks (title, done) VALUES ('Write report', false);
-- Read
SELECT id, title, done FROM tasks WHERE done = false;
-- Update
UPDATE tasks SET done = true WHERE id = 7;
-- Delete
DELETE FROM tasks WHERE id = 7;
-- The same operations in a REST API:
-- POST /tasks, GET /tasks/7, PATCH /tasks/7, DELETE /tasks/7Readers ask
What is a CRUD app?
A CRUD app is an application whose main job is to create, view, edit, and delete records, such as an inventory manager or an admin panel. Most business software starts out as CRUD and then adds workflows, rules, and reports on top.
How do CRUD operations map to HTTP methods?
Create usually maps to POST, read to GET, update to PUT (full replacement) or PATCH (partial change), and delete to DELETE. This mapping is a convention of REST APIs rather than a strict rule.
What is a soft delete?
A soft delete marks a record as deleted, for example by setting a deleted_at column, instead of removing it from the database. Queries then filter out soft-deleted rows, and the data can still be restored or audited.
See also
- REST APIBackend & APIs, p. 38A REST API is a web API that exposes data as resources identified by URLs and lets clients read or change them using standard HTTP methods.
- SQLDatabases, p. 40SQL is the standard language for working with relational databases, used to create tables and to insert, query, update, and delete the data stored in them.
- HTTP MethodBackend & APIs, p. 23An HTTP method is the verb in an HTTP request, such as GET, POST, PUT, PATCH or DELETE, that tells the server what action to perform on the requested resource.
- DatabaseDatabases, p. 6A database is an organized collection of data stored on a computer, managed by software that lets applications save, search, and update it efficiently.
- ORMDatabases, p. 33An ORM is a library that maps database tables to objects in your programming language, letting you read and write data with code instead of raw SQL.
- CQRSSoftware Architecture, p. 10CQRS is an architectural pattern that separates the code that changes data, called commands, from the code that reads data, called queries, into two models.
Spotted a mistake or something missing on this page?Suggest an edit