Meme transcription: Panel 1. Two images of JSON, one is the empty object, one is an object in which the key name maps to the value null. Caption: “Corporate needs you to find the difference between this picture and this picture”

Panel 2. The Java backend dev answers, “They’re the same picture.”

  • expr@programming.dev
    link
    fedilink
    arrow-up
    5
    ·
    8 months ago

    Zalando explicitly forbids it in their RESTful API Guidelines, and I would say their argument is a very good one.

    Basically, if you want to provide more fine-grained semantics, use dedicated types for that purpose, rather than hoping every API consumer is going to faithfully adhere to the subtle distinctions you’ve created.

    • masterspace@lemmy.ca
      link
      fedilink
      English
      arrow-up
      1
      ·
      edit-2
      8 months ago

      They’re not subtle distinctions.

      There’s a huge difference between checking whether a field is present and checking whether it’s value is null.

      If you use lazy loading, doing the wrong thing can trigger a whole network request and ruin performance.

      Similarly when making a partial change to an object it is often flat out infeasible to return the whole object if you were never provided it in the first place, which will generally happen if you have a performance focused API since you don’t want to be wasting huge amounts of bandwidth on unneeded data.