Rethinking CRUD For REST API Designs

Palantir
8 min readadvanced
--
View Original

Overview

The article discusses the limitations of traditional CRUD operations in REST API designs and proposes alternative patterns that better suit modern application needs. It highlights the need for a more flexible approach that accommodates various client workflows and resource interactions.

What You'll Learn

1

How to implement Get-and-Set operations in REST APIs

2

Why traditional CRUD operations may not fit all API use cases

3

When to use optimistic concurrency with timestamp-checked patterns

4

How to design APIs that accommodate concurrent edits effectively

Prerequisites & Requirements

  • Understanding of REST API principles
  • Familiarity with client-server architecture(optional)

Key Questions Answered

What are the limitations of CRUD in REST API designs?
CRUD operations can be too rigid for modern applications, as they often require separate create, read, update, and delete actions that complicate client logic. Many clients prefer a single 'set' operation that can handle all these actions, especially when working with resources identified by unique IDs like UUIDs.
What alternative patterns can be used instead of CRUD?
The article suggests several alternative patterns such as Get-and-Set, Get-and-Patch, and Timestamp-Checked operations. These patterns allow for more flexibility in handling resource updates and concurrency, making them better suited for various client workflows.
How can APIs handle concurrent edits effectively?
Using a timestamp-checked pattern allows APIs to manage concurrent edits by requiring clients to provide the timestamp of their last read. If the server's timestamp matches, the write is accepted; otherwise, the client must re-read the resource and re-compute their changes.
Why is it important to consider search and security operations in API design?
Search and security operations are critical for API functionality and should be integrated into the design from the start. Omitting these can lead to significant backend changes later, complicating the service and potentially impacting client access to resources.

Key Actionable Insights

1
Consider implementing a Get-and-Set operation for your APIs to simplify client interactions.
This approach allows clients to create, update, or delete resources with a single operation, reducing complexity and improving performance.
2
Use timestamp-checked patterns to manage concurrent edits in applications where multiple users interact with the same resources.
This method can prevent data clobbering and ensure that users' changes are not lost, enhancing the reliability of your API.
3
Evaluate the necessity of CRUD operations based on your application's specific workflows and resource management needs.
Understanding the unique requirements of your clients can lead to a more efficient API design that better serves their needs.

Common Pitfalls

1
Failing to account for the need for search and security operations in API design can lead to significant backend changes later.
Many developers overlook these operations initially, only to realize their importance when clients require them, resulting in rushed and poorly integrated solutions.

Related Concepts

REST API Design
Concurrency Management
Optimistic Concurrency Control