Question

I have an online service for which I provide a RESTful API. This API is pretty neat and complete, but my clients would like to access it through an SDK. Now, my clients all have different needs in terms of languages: Go, Python, C#, you name it.

However, being lazy, I notice that the abstraction stays the same, and I have the same functions everywhere. Is there a way to automatize code generation for all of these SDKs, provided the design model is nice and clean? Would UML be useful for example? Or would I only need to create a C libraty matching the API calls and then use some SWIG magic to generate the bindings?

Technologically speaking, I use the Django Rest Framework for the API side, but that should not influence the question.

Was it helpful?

Solution

Of course you can use UML to document your REST API. As in REST it is all about resources and their CRUD methods, I would suggest a restrictive class diagram as a base of this documentation.

Here is an example with some ideas:

enter image description here

From here it is also easy to make an exporter and generate client APIs in any technology. Some UML parsing and selective generation. It's probably kind of time consuming, especially for the newbies, but relativelly straightforward.

However, this neat visual API-spec is already a great input for API-client developers.

UPDATE (after comments)

There are a lot of ways how you can do it in UML, depending on the concrete requirements.

My first idea is to create another package of classes (with stereotype REST-client) or so, that would be connected (via dependency) to corresponding methods thay can execute. Class's atts can be used to store additional info.

Alternatively you can use more illustrative approach and show rest-clients as UML actors. Here is how it looks like:

enter image description here

Note that these special elements (actors and rest-client classes) should be clearly separated in another package in the model and not mandatory displayed on the same diagram with resources. Traceability matrix (supported by some UML tools) is probably much better choice to specify this kind of supplementary information.

If you need more info, please tell me how exactly would you like to handle authentication and permissions.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top