Self document your Spring MVC api

When you are developing web services, documentation is important for the clients that will consume them, basic stuff such as:

emdpointName, HTTP Method, Paramters, Content Type: and so on.

So I found that Spring MVC will let you read that info, so you can expose it, I found it here:

So I changed it a little bit to return the data in json object, the code will be as follows:

Note that you can read everything you Need from RequestMappingInfo object, I am not displaying all of it.

The result of the above code will be something like this, and this can be delivered to the clients consuming your web service along with the acutal documentation, the advantage of this is that they can know what is exacly published in the server, in case the documetation is not updated.


There are tools out there that does this in a more elagant way, http://www.miredot.com/ is one of
them, give them a try :)

Comments