In case we have a search GET REST API endpoint that returns one or zero results for the currently logged in customer, I am wondering what the correct response status code would be, for instance:
api/subscriptions?productId=1
According to the specifications, the customer can either have ONE subscription, or be WITHOUT a subscription for the product.
As far as I understand, and according to the convention, this should be a 200
result, no matter if the result exists or not (the same logic as for a search endpoint that returns a list of objects). I believe it would be incorrect to return 404
here, as this result is only a resource that MIGHT exist?
I understand that this kind of query might even seem as unconventional, as it's purpose is not only to get the subscription, but also to check if it even exists.
I had the idea to wrap the response model in an object result, with the status code 200
:
public class ActiveSubscriptionModel
{
public bool HasActiveSubscription { get; set; }
public SubscriptionModel Subscription { get; set; }
}