nnedoklanov
nnedoklanov

Reputation: 321

What HTTP status code do you use when endpoint is disabled by feature-flag / feature-toggle?

I have been using 503 Service Unavailable or down for maintenance.

However some http client libraries i.e. axios treat 503 as retriable error.

It makes sense to retry it if the response is produced due to high load but 503 also fits the feature-toggle case.

Any suggestion on other codes people use ?

Upvotes: 9

Views: 4522

Answers (2)

Alf
Alf

Reputation: 1

Not sure I agree with the accepted answer's comment "what it doesn't depend on is 'feature flag'". The variations mentioned do make sense, regarding 404 -- not able to find or have access to the resource, 451 -- legal reasons. But, in the case of feature flags, a strong case is made by the RFC itself that a 403 is the correct candidate:

https://www.rfc-editor.org/rfc/rfc7231#section-6.5.3

However, a request might be forbidden for reasons
   unrelated to the credentials.

Feature flags are exactly that -- a way to remove authorization for an operation or resource.

Upvotes: 0

VoiceOfUnreason
VoiceOfUnreason

Reputation: 57377

Status codes are meta data that belong to the "transferring documents over a network" domain. Shared semantics of the status codes is what allows general-purpose HTTP aware components to act intelligently.

So what you should be doing is thinking about the HTTP semantics.

For example, if your server doesn't have access to a current representation of the resource identified by the target-uri of the request, then you should be issuing a 404 Not Found response. If the request is forbidden, then 403 Forbidden. Or 451 Unavailable for Legal Reasons when that is the intended meaning.

In other words: it depends.

But what it doesn't depend on is "feature flag"; that's an implementation detail. The "uniform interface" is a facade that hides those sorts of technical details that vary from one implementation to another. From the outside, your API provides the illusion that your machine is just another boring web server.

Upvotes: 7

Related Questions