Scott, could you please help me to understand the difference between CRUD and REST?
Igor Data
401

Hi Igor,

Sure! CRUD refers to the basic database actions. Anytime you’re interacting with a database (in terms of normal web development usage) you’re probably doing one of the CRUD actions.

CRUD also occurs with an RPC API — it’s purely concerned with what we do with our database. We create records, we read them, we update them, we delete them.

REST API’s mirror the CRUD structure in many ways. Since CRUD is how you interact with the database, and an API exposes endpoints through which you interact with the database, it makes sense there’d be some parallel structure.

What REST API’s commonly do is expose one endpoint per database model (in our case, a note) and then map the four CRUD options onto the four most common HTTP request methods- POST, GET, PUT, DELETE — all on one endpoint.

This is common practice because it simply makes sense — our API is the gateway to the database, so interacting with it should be like interacting with the database.

But while you’ll almost always be doing CRUD actions, there’s no intrinsic reason you need to use REST to get there. An RPC way to do CRUD actions would be to have four endpoints: ‘/createnote’, ‘/getnote’, ‘/updatenote’, ‘/deletenote’. Also totally valid, but perhaps less intuitive.

Hope this helps!

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.