Eric Seifert
Eric Seifert

Reputation: 2022

HTTP Status code and json content for account limits?

I have user accounts that can either be free accounts or paid accounts. The free accounts are limited to creating 5 resources. Users create these by using a JSON API. If the user reaches there account limit of 5 resources, and then tries to create another one, how should I respond? What is the appropriate HTTP status code, and what should be the content of the json?

Also, this is slightly unrelated, when a user deletes a single resource, what should the JSON response content be?

Upvotes: 1

Views: 200

Answers (1)

Peter Brown
Peter Brown

Reputation: 51707

There is an HTTP status code of 402 representing "Payment Required" which seems to be the most appropriate in your case. 401 "Unauthorized" might also be appropriate and may be more widely used. There is more information about the 401 and 402 status codes on Wikipedia. Whichever you chose, Rails has a symbol representation of them.

About 402 from the article:

Reserved for future use. The original intention was that this code might be used as part of some form of digital cash or micropayment scheme, but that has not happened, and this code is not usually used. As an example of its use, however, Apple's MobileMe service generates a 402 error if the MobileMe account is delinquent.[citation needed] In addition, YouTube uses this status if a particular IP address has made excessive requests, and requires the person to enter a CAPTCHA.

Regarding when a resource is deleted, I usually go with 204 "No Content" or 200 "Ok"

Upvotes: 1

Related Questions