3 ms·
So a programming language like Java really doesn't handle sum types (the first example you give) all that well. It's getting better but it's not all there yet.
by crdrost 3y ago
So a programming language like Java really doesn't handle sum types (the first example you give) all that well. It's getting better but it's not all there yet. If you expect those languages to consume then you want the second version.
What I really want is a sort of HATEOAS JSON approach where under some /.well-known/ URL we all agree to serve the data model of the web site -- what I mean is that, if the protocol is called "fairyland" for instance, you access /.well-known/fairyland-schema and you get something back like
{
"fairyland": "v1.0", // schema version
"apiVersion": "1.0.0", // your API version
"auth": [{
"type": "oauth2",
"login": "https://.../"
}],
"featureFlags": {
"redis_agencies": {
"description": "Queries for agencies are cached by Redis, making them eventually consistent.",
"rollout": 0
}
},
"entrypoint": {
// ...
},
"types": {
"Agency": {
"properties": {
"id": {"type": "text", "regex": "some-uuid-regex"},
"license_number": {"type": "text"}
},
"actions": [{
"GetSuppliers": {
"description": "Gets the suppliers associated with this agency",
"action": "GET",
"urlParams": {
"activeOnly": {
"description": "Include only active suppliers?",
"type": "enum",
"values": ["true", "false"]
"default": "true"
}
}
// ...
so the idea is that you could fetch the well-known URL and actually generate a working, crappy little UI website which would browse that API directly. The client would take care of:
1. doing the auth handshake, then making requests starting from the entrypoint,
2. showing a little panel where you could toggle the available feature flags, the protocol would have some X-Fairytale-Features: header that would send these to the backend,
3. when you would get back a type=Agency object, if it had an actions section looking like,
"actions": { "GetSuppliers": "https://api.example.com/v1/suppliers?agencyId=12345" }
then the client would reference that against the already-downloaded actions list and say "aha, I know that I just need to make an HTTP GET request to that URL to get the suppliers, and I know that I can tack on an `&activeOnly=false` param to get the inactive suppliers for that agency as well."
It's a bit of a pipe dream but I keep seeing companies invent completely inconsistent or ad-hoc ways of doing feature flags, relating one request to another, here's how we do auth here... it'd be nice to just specify one approach with a HATEOAS flavor of "each resource can have actions which are links to URLs that specify other resources".
- throwaw12 3y agoI love HATEOS style APIs as a user, but not as a developer building them. Because they're not trivial to build and creates a lot of coupling between systems. For example, if I have a device, which belongs to organization, HATEOS advises me to include a link to `organization` object and how to get there. But, if I am writing a microservice for devices or any other isolated logic from organizations model and how organizations model is exposed externally. Now I need to create coupling between 2 systems and know how to address owner `organization`.
- dragonwriter 3y ago> For example, if I have a device, which belongs to organization, HATEOS advises me to include a link to `organization` object and how to get there. If it is a general purpose interface, you probably want at least one representation of devices that exposes the organization. You may also want one that doesn’t, and you may not want any that do. There’s no violation of HATEOAS in having collections that link to leaf nodes but leaf nodes not linking to collections they may be part of. All HATEOAS really says is that if you want clients to be able to get from the device to the owning organization, then you should include a link to the organization in the representation of the device rather than relying on the client interpreting the structure of the URI of the device to infer the associated organization. Hypertext as the engine of application state does not have strong opinions on what navigation or state transitions are supported, only that those that are supported should be supported via hypermedia techniques of in-representation locators for location, methods with well-defined semantics operating against the resources at those locations, and representation types (e.g., media types), with each serving its particular purpose.
- throwaw12 3y agoregarding your other point about limitations of how statically typed languages parse data. How about making this kind of response: class Organization: id: string name: string ... couple of common fields ... supplier: Supplier # supplier specific fields agency: Agency # agency specific fields ....
- 3y ago