How to add REST API upsert support
Blog post from Tyk
In the article by Jennifer Craig, the concept of adding upsert support to a REST API is explored, highlighting its efficiency in reducing the number of HTTP requests needed to check for the existence of a resource before creating or updating it. An upsert, commonly used in databases like MongoDB and PostgreSQL, combines an insert with an update operation to optimize API interactions by automatically creating or updating records in a single statement. The article details three approaches to implement upsert behavior in APIs: using a PUT request with a consumer-supplied identifier, a POST request with unique property detection, and a POST request with unique composite property detection. Each approach is designed to cater to different requirements, ensuring that resources are updated or created efficiently without unnecessary network traffic. The importance of documenting this behavior in API documentation is emphasized to avoid confusion among developers. The article underscores upserts' ability to streamline interactions and reduce concurrency issues, making them a valuable addition to modern API design.