0

Suppose I have a sports player endpoint. It gives me their dataOfBirth, salary, firstName and lastName. Great covers all sports. Rugby, Soccer, you name it...

Then someone wants goals scored for the soccer endpoint and someone else wants number of tries for the rugby player. So now I could stick with one Resource and just have goals null when its a rugby player and vice verse. Or I could do separate endpoints. What's better?

I appreciate pure REST, everything should be dynamically discoverable so you can do either way. This is pragmatic REST.

More Than Five
  • 9,959
  • 21
  • 77
  • 127

1 Answers1

1

I think another good option in your case is to design a resource (player) which has all the properties the different sports have in common (such as name, sports, etc) and you add a generic property (e.g. statistics) which is an array of key/value pairs for the distinct properties. This allows you to add any information to the resource without setting something to null.

Example:

[
  {
    "name": "Player1",
    "sports": "soccer",
    "statistics": [
      "goals": 5
    ]
  },
  {
    "name": "Player2",
    "sports": "basketball",
    "statistics": [
      "points": 12
    ]
  }
]
Philipp
  • 470
  • 2
  • 10