javarestpostgetbest-in-place

Include an Id in a HTTP POST request body that supports wildcard search


There is a java, REST API based web application which uses HTTP POST request to search a user specific parameters including wildcards. The same application uses GET request to get specific resources using Ids. Recently an architect came to an idea of using that same POST request to load specific resources using IDs instead of using typical GET request which has a pattern GET some/resource/by/{id}. Literally the whole idea is to use that same POST request which is used for a search, to load resources by Ids. Is it a bad practice? I would like to hear your thoughts, ideas and conclusions.


Solution

  • Yes, using an HTTP POST request to retrieve resources by ID, especially when that resource can be retrieved safely via GET, is generally considered bad practice in RESTful design.

    Here’s a breakdown of why and when you might deviate:

    Violates HTTP Semantics

    Hurts Cacheability and Performance

    Breaks RESTful Conventions

    When It Might Be Acceptable

    Complex Search with Filters or Wildcards

    For large or complex queries (e.g., hundreds of filters, multiple IDs), POST is acceptable due to:

    So you should decide on your situation...