REST API Best practice ? return Empty object vs no object

5

let's say i have an API that returns users wallet balance and List of wallet transactions which is going to expiry

response = {
   user_balance: 20
   expiring_credits : [
     {object 1 }
     {object 2}
   ]
}

in case if user dont have any expiring transactions we can format respose in 2 ways option 1

 response = {
   user_balance: 20
 }

option 2

  response = {
    user_balance: 20
    expiring_credits : []
  }

which is the ideal option or best practices? and why? looking for some expert insights. many thanks.

Share
Improve this question

Comments

Popular posts from this blog

Storage in React Native

react-native vs reactXP

Implementation of a function object “power” operator in Raku