resthttpresponseapi-designfeaturetoggle

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 ?


Solution

  • 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.