RESTful POST request, If the record already exists on POST data, do we return 200 OK or 304 Not Modified?

Manjunath Reddy

I have a POST request endpoint, where user repeatedly post the data. Before I insert the data to database, based on user request,I do check if the record already exists. - If record already exists, I return 200 OK with response body containing the table_id and status - If record does not exists, I create new record and return 200 OK with response body containing table_id and status

Basically in both the cases, user get status 200. As user it might be confusing as one couldn't be able to distinguish whether its a new record or existing record.

I thought I would return 304 with response body and inform the consumer telling that This request is "Not Modified", in this way consumers would make a decision.

Is it a good practice or is there alternative approach in RESTful principals.

Remy Lebeau

304 is intended to be used only for a Conditional GET response, to indicate that the requested content has not changed since the last time the client asked for it. It is not appropriate for a POST response.

For a POST response, use 201 if a new record is created, otherwise use 200 or maybe 409 instead.

See the following for some helpful tips in designing REST APIs:

Using HTTP 304 in response to POST

HTTP response code for POST when resource already exists

Creating an efficient REST API with HTTP

REST lesson learned: Avoid 204 responses

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Block HTTP POST Request if a record already exists in the database

From Dev

Post Does Not Return 200 OK in Liberator Clojure

From Dev

OPTIONS return 204, POST return 200 but data is not entered in db

From Dev

Not able to post JSON Data to MVC Action Method using $.AJAX but I get a Post 200 OK Response

From Dev

Dynamic CSS is not being cached by browsers - response returns 200 OK instead of 304 Not Modified

From Dev

AWK print record posterior to matched record (the post that already exists is about fields, not records)

From Dev

How to return data in POST request (django/tastypie)

From Dev

How to return data in POST request (django/tastypie)

From Dev

Use Post Request to retrieve data and return a List

From Dev

rest/javax/jersey/grizzly: is it mandatory to return OK (200) response code for POST requests?

From Dev

Why do we need redirect after sending post request?

From Dev

RESTful url: PUT or POST for a single record

From Dev

Is it ok to use POST for a GET request on the server

From Dev

Ajax request return 200 OK but error instead of success

From Dev

Spring RestTemplate exchange POST HttpClientException with any non 200 OK response

From Dev

Phoenix return 200 status code for POST

From Dev

Flask Restful accept a list in a post request

From Dev

HTTP POST request in the Spring RESTful app

From Dev

Django post request data

From Dev

No data in params on POST request

From Dev

POST request with form data

From Dev

RESTful: When is it OK to POST without creating a resource on server?

From Dev

How do I return strings from an asynchronous POST request?

From Dev

POST Request is turning to 200 OPTIONS in Phoenix but not sending the following POST

From Dev

Swift - Return data from NSURLSession when sending POST request

From Dev

How to structure httr POST request to return site data?

From Dev

AngularJS Post Request not catching JSON data return from PHP

From Dev

POST request: return status reports

From Dev

Why do we need res.on('data'... defined for POST even if we are not doing anything with the data?

Related Related

  1. 1

    Block HTTP POST Request if a record already exists in the database

  2. 2

    Post Does Not Return 200 OK in Liberator Clojure

  3. 3

    OPTIONS return 204, POST return 200 but data is not entered in db

  4. 4

    Not able to post JSON Data to MVC Action Method using $.AJAX but I get a Post 200 OK Response

  5. 5

    Dynamic CSS is not being cached by browsers - response returns 200 OK instead of 304 Not Modified

  6. 6

    AWK print record posterior to matched record (the post that already exists is about fields, not records)

  7. 7

    How to return data in POST request (django/tastypie)

  8. 8

    How to return data in POST request (django/tastypie)

  9. 9

    Use Post Request to retrieve data and return a List

  10. 10

    rest/javax/jersey/grizzly: is it mandatory to return OK (200) response code for POST requests?

  11. 11

    Why do we need redirect after sending post request?

  12. 12

    RESTful url: PUT or POST for a single record

  13. 13

    Is it ok to use POST for a GET request on the server

  14. 14

    Ajax request return 200 OK but error instead of success

  15. 15

    Spring RestTemplate exchange POST HttpClientException with any non 200 OK response

  16. 16

    Phoenix return 200 status code for POST

  17. 17

    Flask Restful accept a list in a post request

  18. 18

    HTTP POST request in the Spring RESTful app

  19. 19

    Django post request data

  20. 20

    No data in params on POST request

  21. 21

    POST request with form data

  22. 22

    RESTful: When is it OK to POST without creating a resource on server?

  23. 23

    How do I return strings from an asynchronous POST request?

  24. 24

    POST Request is turning to 200 OPTIONS in Phoenix but not sending the following POST

  25. 25

    Swift - Return data from NSURLSession when sending POST request

  26. 26

    How to structure httr POST request to return site data?

  27. 27

    AngularJS Post Request not catching JSON data return from PHP

  28. 28

    POST request: return status reports

  29. 29

    Why do we need res.on('data'... defined for POST even if we are not doing anything with the data?

HotTag

Archive