Page MenuHomePhabricator

Omit fields instead of making the value null
Closed, DeclinedPublic

Description

Mediawiki REST API responses may provide null values.

  • BETTER: It would be better to mark the value as undefined instead of null. Then TypeScript clients don't need to do something like this.
  • BEST: It would be best to omit those fields. This would also save some network bandwidth and parsing overhead on the client.

Is this something that could be changed? Are there reasons for using null?
I do appreciate the consistency of the API and would like to see that continued. So, if this behavior can be changed it should be changed for all endpoints.

Event Timeline

BPirkle subscribed.

undefined is a Javascript construct, not a JSON one. While I recognize that undefined would be useful in the situation mentioned in the task description, we want REST responses to conform to valid JSON schemas.

As for completely omitting values, that does occur in some situations (you won't get an newer value from /page/{title}/history if you're on the first page of results, but you will on the other pages.

In the cases where null is returned, as opposed to omitting the value, that was generally an intentional decision for the contract of that particular response. I don't have all those original discussions on hand. But if there are specific cases where you'd like that reconsidered, feel free to post a more specific task (or one task with a bunch of them would be a fine starting place too).