0

API return data in json format response: { name : 'John' creditCardNum: '123456789' }

What's the best practice to identify the creditCardNum has no value (maybe not yet setup the credit card) or the request user has no permission to view credit card info?

I am thinking of : No Value : { name : 'John' } No permission : { name : 'John' noPermissionCreditCardNum : true }

But for no permission, I need to add another field for identify it is no permission.

Vfire
  • 41
  • 4
  • Why not just check if the `creditCardNum` property has a value or not? – Obsidian Age Dec 06 '17 at 01:43
  • Return HTTP status 200 (OK) with message body containing all data when user has permissions. Return 403 (Forbidden) when user is now allowed to access resource (https://stackoverflow.com/questions/3547474/correct-http-status-code-when-resource-is-available-but-not-accessible-because-o) with specific error message. – Justinas Jakavonis Dec 06 '17 at 08:19
  • I need to show different messages for No-Value and No-permission. – Vfire Dec 06 '17 at 15:56
  • I cant just return 403 for whole of json data, because only creditCardNum has permission issue. – Vfire Dec 06 '17 at 15:58

0 Answers0