Haufe-Lexware / api-style-guide

Haufe API Style Guide

Home Page:https://haufe-lexware.gitbooks.io/haufe-api-styleguide/content/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Sharpen argument for hypermedia and add list of client libs/projects

hlgr360 opened this issue · comments

From an email convo:

Die _link Elemente erlaube eine starke semantische Entkopplung des Clients vom Backend.

Das Prinzip ist relativ einfach .. anstelle das Wissen über die konkrete URL Struktur der API in den Client hart zu verdrahten, kennt der Client nur die Relationship Attribute Values. Um eine bestimmte Operation mit einem bestimmten Relationship Attribute Value durchzuführen, findet der Client das matching _link Element und benutzt die darin embedded URL ‘as-is’ (mit der Exception fuer den Backend Server bei Injektion des ‘Forwarded’ Header durch den vorgeschalteten APi Management Proxy)

Das erlaubt eine spätere Änderung der URL Struktur der API, ohne dass der Clients verändert werden muss. Das bedingt natürlich auch, dass Ihr die _link Elemente nicht einfach ignoriert, sondern sie entsprechend der Spezifikation nutzt. Eine Google Search zeigt eine ziemlich grosse Anzahl von client libs, die ihr entsprechend fuer Eure Anwendung evaluieren könnt.

Juan Martinez, Salvador @JuanS 10:45 AM
Oh nice, thats a lot of interesting material to read, I haven't read it all yet, but i will, in the meantime, related to some of the topics you mentioned above, my personal take on how to use hypermedia:

Without hypermedia, clients had to make requests, read the values of the response (state) and according to the values, then implement business logic to decide what to do next. With Hypermedia, if you offer state through links, with possible actions (like a finite-state-machine) then on the clients, one can just perform coding around the presence or absence of links.

So basically the target is to remove all the domain/business knowledge from the client side, and replace it with "protocol" knowledge through links. This way you remove duplicated implemented logic, effectively reducing the amount of changes that would have been breaking ones, achieve loose coupling, etc. But also, at the same time, need to carefully design hypermedia, because, the risks of making everything accessible through links can lead to a really chatty API, which at the end can do more harm than good. This is one of the reasons I also like consumer-driven-contracts approach, it makes those 2 concerns easier to address.
👍🏻 1

Reinhardt, Holger @reinhardth 10:51 AM
true ... and you went way deeper the rabbit hole than I would (which is a weird way of making a compliment) 😉
to me they are two ways of coupling I have observed .. there is syntactical coupling ... which usually involves interfaces directly or indirectly generated from an implementation .. you change the implementation, you change the interface
this was the original sinn of WebServices .. it was essentially a functional interface across the network ... you changed one side .. you had to change everyone relying on it too ... which did not scale for even mildly complex environments
then there is a more hidden kind of coupling ... I call it semantic coupling ... it is the embedding of knowledge about the API/interface in the client
a particuar way how URL's are constructed
hardcoding server IP's
some stuff you know becaue you have access to the server code etc
this coupling is non-obvious but it falls on your feet the moment you change something fundamental about the server .. maybe you move the server to a difference hostname or ip
or you change the urls
or you change a particular behavior (do this and then do this) which the client had been relying on
and usually that hits you when you are already operating at some scale ... and then you are in a place of real pain
you either not change it (and can not evolve) or you change it and break a lot of clients
most REST-light or pragmatic REST API's fall into that category
this is where hypermedia comes in .. sure, in the ideal world you can do everything you described above (de-duplication business logic etc).
but I would already be happy if it were simply preserving our ability to evolve without breaking existing clients which are owned and managed by different teams or differet orgs
the need for coordination is the enemy of speed