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

flutter websocket connection issue

Webpack 5 and Storybook 6 integration throws an error in DefinePlugin.js

Meaning of `{}` for return expression