Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTTP Status Code for Resource not yet available

Tags:

I have a REST endpoint accepting a POST request to mark a code as redeemed. The code can only be redeemed between certain dates.

How should I respond if someone attempts to redeem the code early?

I suspect HTTP 403, Forbidden, is the right choice but then the w3c states that "the request SHOULD NOT be repeated" whereas in this case I would anticipate the request being repeated, just at a later date.

like image 683
Dan Midwood Avatar asked Jun 18 '12 09:06

Dan Midwood


People also ask

What is Status 204 no content?

10.2.5 204 No ContentThe server has fulfilled the request but does not need to return an entity-body, and might want to return updated metainformation. The response MAY include new or updated metainformation in the form of entity-headers, which if present SHOULD be associated with the requested variant.

What is 204 status code HTTP?

The HTTP 204 No Content success status response code indicates that a request has succeeded, but that the client doesn't need to navigate away from its current page.

What is a 202 status code?

The HyperText Transfer Protocol (HTTP) 202 Accepted response status code indicates that the request has been accepted for processing, but the processing has not been completed; in fact, processing may not have started yet.

What HTTP status code should be returned if a requested resource is not found?

The HTTP 404 Not Found response status code indicates that the server cannot find the requested resource.

What is the HTTP status code of a resource request?

When you GET a resource your client is asking the server for a representation of a resource in the current state it is in. That could be a picture of a bird, it could be a Word document, it could be the current outside temp. The HTTP protocol doesn't care. The HTTP status code corresponds to the result of that request.

What does the HTTP status code success mean?

This status code is primarily intended to be used with the Link header, letting the user agent start preloading resources while the server prepares a response. The request succeeded. The result meaning of "success" depends on the HTTP method:

How to resolve http-status-404-the requested resource is not available?

Restart the Web Help Desk service (Stop and start Web Help Desk). Admin Items URL Name HTTP-Status-404-The-requested-resource-is-not-available

Are HTTP status codes extensible?

3 People often forget that HTTP status codes are extensible. HTTP status codes are extensible. HTTP applications are not required to understand the meaning of all registered status codes, though such understanding is obviously desirable.


2 Answers

409 Conflict

The request could not be completed due to a conflict with the current state of the resource. This code is only allowed in situations where it is expected that the user might be able to resolve the conflict and resubmit the request. The response body SHOULD include enough information for the user to recognize the source of the conflict. Ideally, the response entity would include enough information for the user or user agent to fix the problem; however, that might not be possible and is not required.

403 Forbidden makes more sense if they are trying to redeem a coupon that has already been redeemed, though 410 Gone seams elegant in this situation as well.

404 Not Found isn't ideal because the resource does in fact exist, however you can use it if you don't want to specify a reason with the 403 or if you want to hide the existence of the resource for security reasons.

If you are using HATEOAS, then you can also head you clients off at the pass (so to speak) by only including a redeem hypermedia control in the coupon resource (retrieved via a GET) when the coupon can be redeemed; though this won't stop overly bound clients from trying to redeem it anyway.

like image 172
Tom Howard Avatar answered Nov 09 '22 23:11

Tom Howard


Since Rest URLs should represent resources I would reply with 404 - Not Found
The resource is only available between certain dates, so on any other date it is not found.

like image 40
VolkerK Avatar answered Nov 10 '22 00:11

VolkerK