Difference between REST and CRUD

  • I learned REST and it feels a lot like CRUD (from what I have read about CRUD).

    I know they are different, and I wonder if thinking they are similar means I don't understand them.

    Is it that REST is a "superset" of CRUD? Does it do everything CRUD does and more?

    Thinking they are similar means that you _do_ understand them. In reading the answers, I see a surprising and what I consider to be incorrect level of _not_ acknowledging the similarities between the concepts. I believe that the correct way to understand REST _is_ to think of it as "CRUD for HTTP resources". If you understand what an HTTP resource is (its not the same as a database record obviously) and you know what CRUD is, then describing REST as "CRUD for HTTP resources" is a correct and succinct way to convey the essence of REST.

  • Javier

    Javier Correct answer

    9 years ago

    Surprisingly, I don't see in the other answers what I consider the real difference between REST and CRUD: what each one manages.

    CRUD means the basic operations to be done in a data repository. You directly handle records or data objects; apart from these operations, the records are passive entities. Typically it's just database tables and records.

    REST, on the other hand, operates on resource representations, each one identified by an URL. These are typically not data objects, but complex object abstractions.

    For example, a resource can be a user's comment. That means not only a record in a 'comment' table, but also its relationships with the 'user' resource, the post that comment is attached to, maybe another comment that it responds to.

    Operating on the comment isn't a primitive database operation, it can have significant side effects, like firing an alert to the original poster, or recalculating some game-like 'points', or updating some 'followers stream'.

    Also, a resource representation includes hypertext (check the HATEOAS principle), allowing the designer to express relationships between resources, or guiding the REST client in an operation's workflow.

    In short, CRUD is a set primitive operations (mostly for databases and static data storages), while REST is a very high-level API style (mostly for web services and other 'live' systems).

    The first one manipulates basic data, the other interacts with a complex system.

    @Javier Thanks for setting them apart. I used REST learning Rails and I got the impression it was a replacement for CRUD (which I learned about since... the name that is, I was already using it, just didn't know what to call it)... You turned REST vs CRUD from comparing 2 apples to comparing apples and oranges. Thanks

    @Maudicus: i think it's very common, since RoR includes a CRUD layer (as most (every?) framework does), and it makes it easy (automatic?) to add a REST API on top of that, it's easy to think that's all what REST is. But then you can add functionality on top of CRUD but behind the REST API, making them more and more different.

    Your answer is correct, but the example isn't optimal: a comment can boil down to a single db row, and isn't it possible to implement dynamic changes to related objects with db triggers? I feel there's a little more than just crud operations in restful api though, and your answer clearly carry that feeling well.

    So...same thing, different layer :)

    Thank you so much for expressing this! I'd add that the limitation of HTTP verbs to CRUD operations result in implementing REST literally as CRUD, with lots of tools that generalize the CRUD boilerplate and miss a place for this custom "operating on a comment" logic.

    @Javier Or you can add another REST API on top of your existing one(s) to add functionality. :-)

    But with REST, they COULD just be data objects, right? If the server defined it that way and the client was expected to treat them that way? And it would still be REST?

License under CC-BY-SA with attribution


Content dated before 6/26/2020 9:53 AM