We are using HTTP protocol to trigger an asynchronous action on the web server, which later in the background loads data from another server and writes them into our server's database.
┌──────┐ ┌──────┐ ┌───────────┐
│client│ │server│ │data-source│
└──┬───┘ └──┬───┘ └─────┬─────┘
│ │ │
│ ?METHOD? /sync-data │ │
│────────────────────→│ │
│ │ │
│ 202 ACCEPTED │ │
│←────────────────────│ │
│ │ │
│ │ Fetch data │
│ │───────────→│
│ │ │
│ │ [data] │
│ │←───────────│
│ │ │
│ │───────╮ │
│ │ Store │ │
│ │ data │ │
│ │←──────╯ │
│ │ │
┌──┴───┐ ┌──┴───┐ ┌─────┴─────┐
│client│ │server│ │data-source│
└──────┘ └──────┘ └───────────┘
(Credit for ASCII sequence diagram online tool: https://arthursonzogni.com/Diagon/#Sequence)
The question is, which HTTP method is the best for the call?
I am not asking for an opinion, but for well-informed answer which of the HTTP method is more corresponding to the industry standards in this particular case.
I collected arguments for and against each of the method.
In "Normal purpose" I am influenced how we use CRUD-HTTP mapping with REST.
| Method | Normal purpose | Why to use it in my case | Why not |
|---|---|---|---|
| GET | Read data | • Request does not immediately change server status • No body • Most simple for testing |
• Eventually server status changed |
| POST | Create a new object | • It is a common method used for changes | • The character of the triggered asynchronous action is not Create • After the method returns, the server status is not yet changed |
| PUT | Replace an existing object | • Sounds fine, but... | • The data which will replace the server data are not part of this request • After the method returns, the server status is not yet changed |
| DELETE | Delete an existing object | N/A | N/A |
| PATCH | Partially update an existing object | N/A | • We are not changed "some fields of a record" • The data which will replace the server data are not part of this request • After the method returns, the server status is not yet changed |
EDIT After receiving downvoting and close suggestions as "Opinion-based"
I am not asking anyone's opinion, what I want is to know which of the HTTP method corresponds the best with the above mentioned use case, according to standards. I might have some opinion on it, but I want my opinion to be supported by what the industry standard is. My arguments and counter-arguments collected in the table might look like "opinion-based", but that's how people are searching for an answer - sorting out what they know so far.
Please consider this before quickly connecting the phrasing "which is the best" with "opinion-based".
POST- because you will be you are sending data to perform actions, not to get information. Also it's default method to send information to server.PUT/PATH/DELETEis more for REST API and is "made up" (HTML forms does not have these methods)