Page MenuHomePhabricator

Should the REST API return null/empty or should the property be missing?
Closed, ResolvedPublic

Description

While creating a new MediaWiki-REST-API endpoint in the IP Info extension T260603, we discovered that we may have properties that are missing. These properties could be scalars, arrays, or nested objects. Does Platform Engineering recommend returning these values as empty ({}, [], null) or should the property be removed from the output completely? What about nested objects? Should every property always exist in the output?

We do not have a preference, but would like the APIs to be consistent either way.

Event Timeline

dbarratt updated the task description. (Show Details)
Pchelolo claimed this task.
Pchelolo added a subscriber: Pchelolo.

According to https://www.mediawiki.org/wiki/Core_Platform_Team/Initiative/Core_REST_API_in_Mediawiki/Design_principles

Empty properties should have the value "null". If a property has no value, we should include the property name in the JSON output, with the value null.

@Pchelolo That is super helpful, thank you so much!

@Pchelolo related question, should nested objects be null or should their (scalar) properties be null?

As an example, let's say we have a revision

{
  "author": null
}

OR

{
  "author": {
    "id": null,
    "name": null
  }
}

I think the former,

{
  "author": null
}