Writing client code that works with an HTTP-based API is generally a lot of work. Therefore, such APIs often have client libraries in different programming languages, which wrap the HTTP operations in a more convenient language-specific API. We would like to have client libraries that wrap the Knora APIs, especially in TypeScript and Python. But maintaining such libraries is also a lot of work: when the API changes, the libraries have to change. We would therefore like to automatically generate the parts of these libraries that are most likely to change over time.
Most of the information we need to generate such code is already in the Knora API ontologies, so the first step is to make a code generation framework that can generate, say, TypeScript code from ontology definitions.
Andreas Aeschlimann has already developed the basis of a TypeScript client library for Knora.
So far, it focuses on the Knora admin API, and contains class definitions that correspond to definitions in the Knora admin API ontology. I’m working on generating these definitions automatically, so that when the admin API ontology changes, the corresponding TypeScript class definitions can be regenerated accordingly. The generated code could be put in a GitHub repository so it would be easily accessible to developers.
Work in progress is in Knora PR 1259.
The admin API is a good place to start, because it uses plain JSON, rather than JSON-LD, which is used in the Knora API v2.
Once that works, the next steps are:
- Support JSON-LD and Knora API v2.
- Support Python.
- Generate project-specific library code. This way, a project with a class like
Bookcould get an automatically generated
Bookclass in TypeScript.