1
  1. Search - request contains query parameters e.g. search term and pagination values. No changes/data is persisted to backend.

I currently use GET with query parameters here.

  1. Data conversion - request contains data in format A and server sends data in format B. No changes/data is persisted to backend.

I currently use POST with request parameters here.

2 Answers2

1

For your Data Conversion use case (which seems to be more of a function that working with a representation of something on the server), the answer is more grounded in higher-level HTTP verb principles than RESTful principles. Both cases are non-idempotent: they make no changes to the server, so GET should be used.

This question has a good discussion of the topic, especially this comment:

REST and function don't go well together. If an URL contains function, method, or command, I smell RPC – user1907906

busse
  • 1,761
  • 14
  • 25
0

Search - request contains query parameters e.g. search term and pagination values. No changes/data is persisted to backend.

If the request is supposed to generate no changes on the back end, then you are describing a request which is safe, so you should choose the most suitable safe method - GET if you care about the representation, HEAD if you only care about the meta data.

Data conversion - request contains data in format A and server sends data in format B. No changes/data is persisted to backend.

Unless you can cram the source representation into the URL, POST is your only reasonable choice here. There is no method in HTTP for "this is a safe method with a payload".

In practice, you could perhaps get away with using PUT rather than POST -- it's an abuse of the uniform interface, but one that allows you to communicate at least the fact that the semantics are idempotent. The key loophole is:

there is no guarantee that such a state change will be observable, since the target resource might be acted upon by other user agents in parallel, or might be subject to dynamic processing by the origin server, before any subsequent GET is received. A successful response only implies that the user agent's intent was achieved at the time of its processing by the origin server.

Community
  • 1
  • 1
VoiceOfUnreason
  • 52,766
  • 5
  • 49
  • 91