javaspringspring-mvcspring-hateoas

How to self describe a REST api with Spring?


I'm using spring-mvc to create servlets like:

@RestController
public class MyServlet {
   @GetMapping("/test")
   public MyRsp test(MyReq req) {
         //...
   }
}

Now if the user accesses the root of my app localhost:8080/my-app, it should show a list of GET and POST methods available. At best with possible input parameters, acceptable headers etc.

Question: is that possible with any spring framework, like HATEOAS?

I'd expect a framework to auto detect any @RestController and included methods.

Or would I have to create that overview page myself?


Solution

  • Swagger 2 is an another option. read the following to know more about swagger and how to set it up.

    Setting Up Swagger 2 with a Spring REST API

    You can also create swagger definition for your rest apis, which can be used by the clients to generate client classes.

    Also the swagger ui can be used to test/invoke your APIs. swagger provides a user interface where you can input all the api inputs such as query params, path params, request body, headers.

    Sample Swagger UI