News for hackers. Stuff that matters.
Re:How to Design Better APIs by kortex on Saturday March 12, 2022 @09:32AM (#30651634)
I think I'm with Jack on this one, at least when it comes to REST interfaces. When I query GET /bar/123, I want an object with a Bar protocol/content-type. I don't want a Envelope[Bar]. What if it's any data type other than json-isomorphic, e.g. image or video? Is /videos/123.mp4 going to return a json object like

    {"data": <base64_encoded_video>, "status": "whatever"}
Of course not!

You already have an envelope, it's the HTTP protocol. The real trick is generically mapping data structures to HTTP responses with headers. In fact HTTP-response-shaped-objects make halfway decent general purpose envelopes in the business logic itself. They are basically Result[T, E] but with even more metadata available.

Re:How to Design Better APIs by bcrosby95 on Saturday March 12, 2022 @10:58AM (#30652221)
We wrap the response body because it's important to give clients of an API endpoint, something that they will use to query/modify data, a clear indicator of the application response status. We do this in the response body because http status codes aren't good enough, and people tend to miss headers. It's hard to miss it when it's part of the body.

And no, we don't do that for static content for a simple reason: static content isn't served from our API servers.