ApiDesign
API Design
Socket programming
Operations
Send on the left; Receive on the right
Challenges
Marshal/Unmarshal
Challenges: For a remote procedure call, a remote machine may:
Different sizes of integers and other types
Different byte ordering. E.g. Big endian / little endian
Different floating point representations
Different character sets
Different alignment requirements
How to define the grammer for remote operations. E.g. How to represent an add operation? Use '+', 'add' or number '1'
How to represent the parameters for functions. E.g. Polish notation, reverse polish notation.
Challenges: Reference variables
What we pass is the value of the pointer, instead of the pointer itself. A local pointer, pointing to this value is created on the server side (Copy-in). When the server procedure returns, the modified 'value' is returned, and is copied back to the address from where it was taken (Copy-out).
This approach is not foolproof. The procedure 'myfunction()' resides on the server machine. If the program executes on a single machine then we must expect the output to be '4'. But when run in the client-server model we get '3'. Why ? Because 'x, and 'y' point to different memory locations with the same value. Each then increments its own copy and the incremented value is returned. Thus '3' is passed back and not '4'.
Service discovery
How to do service discovery. E.g. What functionalities a remote service support.
Performance and resiliency
What to do when faced with performance and resiliency conditions, etc.
RPC history: SUN RPC / ONC RPC
Use case
NFC protocol mount (put a remote directory on a local path) and nfsd (read / write files) commands.
Components
SUN RPC flowchart
XDR means external data representation.
Utilities for generating stub
Service discovery with portmapper
Limitations
Error prone compression and decompression process.
Hard to modify the protocol.
ONC RPC is function oriented, not object oriented.
XML based protocols
When compared with ONC RPC
It has the following benefits:
ONC RPC is binary based. XML allows client and server accepted data transformation to have some inconsisteny. e.g. changing the order of elements will not result in any error.
It is object oriented instead of function oriented.
SOAP
WSDL protocol
WSDL protocol could be used to generate client's stub.
UDDI
Universal description, discovery and integration
Sample request
Real world
Netflix
GraphQL at Netflix:
API redesign
Embracing the Differences : Inside the Netflix API Redesign
Redesign the Netflix API:
API specification
Open API spec: https://swagger.io/specification/
Google API: https://cloud.google.com/apis/design
Handyman API guidance: http://apistylebook.com/design/topics/governance
References
The Design of Web APIs: https://www.manning.com/books/the-design-of-web-apis
API design patterns: https://www.manning.com/books/the-design-of-web-apis
API security in action: https://www.manning.com/books/api-security-in-action
API design guidance: https://tyk.io/api-design-guidance-long-running-background-jobs/
Geektime [Chinese]:
Last updated