←back to thread

JSON Patch

(zuplo.com)
299 points DataOverload | 3 comments | | HN request time: 0s | source
1. brap ◴[] No.41881677[source]
This declarative approach is always limited compared to an actual programming language (e.g. JS), and so over time things get bolted on until it’s no longer truly declarative, it’s just a poor man’s imperative language. A good example is HCL which is a mess.

What about just stringifying a JS function?

replies(1): >>41882345 #
2. alxmng ◴[] No.41882345[source]
This is essentially the RPC vs REST debate. Do you want your API to be a schema of data types (REST), or a list of function signatures (RPC)?
replies(1): >>41887808 #
3. brap ◴[] No.41887808[source]
You raise a good point, but REST isn't quite declarative, and RPCs isn't quite what I'm proposing.

REST is great but I wouldn't exactly call it declarative, it relies on HTTP verbs, plus there are times when you simply can't express things with pure REST so usually you break the textbook pattern with something like POST /resource/doSomething.

As for RPCs, you have to predefine the operations you want to expose as part of your schema, which is even less flexible than what I'm proposing. Imagine for example that instead of passing a JSON Patch string you'll pass a real JS arrow function (with some limitations, e.g. no closure state). It allows for max flexibility, the user doesn't have to learn any APIs, plus the implementation becomes trivial. It's kind of like SQL without inventing a new language.