Thanks for the encouragement. I have now gotten started with it.
I took your advice and focused on what I need short term (categories, topics, posts) and I am now something like 30% of the way there (the rest should go faster since I now have an idea how to do it)
What I’ve done is to create a Swagger Specification, available at discourse_swagger/discourse_swagger.yml at master · erkist/discourse_swagger · GitHub (as of this writing it only supports site.json and categories.json)
This specification can be used to generate a Java API library (or any other supported language), which can then be invoked as below:
ApiClient client = new ApiClient();
client.setBasePath("http://192.168.56.2");
DefaultApi api = new DefaultApi(client);
((ApiKeyAuth) client.getAuthentication("api_username")).setApiKey("erki");
((ApiKeyAuth) client.getAuthentication("api_key"))
.setApiKey("35b1416dda787a137dddca95170a549e0445507fcabcd009c09d3569cdb527b7");
Site site = api.getSiteInformation();
String nameOfFirstGroup = site.getGroups().get(0).getName();
Categories categoriesResponse = api.getCategories();
String nameOfFirstCategory = categoriesResponse.getCategoryList().getCategories().get(0).getName();
As you see the generated API is strongly typed, and the name and structure closely reflects the REST API responses.
I aim to continue expanding it a bit, but I’m not sure I’ll ever get to a full implementation. Still, if this helps anyone other than me, that would be awesome. And if someone wants to help, even better! And even if I’m the only user, I’m still satisfied since I’ve gotten the opportunity to learn YAML, Swagger, JSON Schema and parts of the Discourse source code ![]()