If I have an endpoint where its function sometimes inserts data, other times reads data, should it be split into two endpoints, or one POST endpoint?

Viewed 17

Basically if there is fresh data in the database, I will directly read that data, otherwise if the data is older, I would be computing new data to insert, and then read that inserted data. Which is better, putting that logic under one POST endpoint or splitting the insert part under a POST endpoint, and the get part under a GET endpoint, then calling the POST endpoint which would redirect to the GET endpoint?

1 Answers

Assuming that "computing new data to insert" doesn't involve reading information out of the HTTP request body, you should normally use GET here.

We choose HTTP methods based on the semantics of the request ("give me the current representation of the resource") not on the implementation details of the request handler.

Related