Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swagger and RESTful spring hateoas resources

In my RESTful API, all resources are extending the Spring's ResourceSupport base, in order to ensure hateoas principals by design. For example:

public class PoolResource extends ResourceSupport {
    private String name;
    ...
}

I'm also using Swagger, and i was wondering: is it possible to configure the swagger-ui somehow, to ignore the properties coming from ResourceSupport?

enter image description here

(Swagger-ui provides a nice and easy frontend of the API. As one of the major benefits of using Swagger, the API is easy to understand and play around with the API for those, who are not even familiar with the REST API... as long as the "links" and "rels" come into the picture.)

like image 216
István Békési Avatar asked Jan 21 '15 13:01

István Békési


People also ask

What is HATEOAS in RESTful web services?

What is HATEOAS? HATEOAS is a constraint on REST that says that a client of a REST application need only know a single fixed URL to access it. Any and all resources should be discoverable dynamically from that URL through hyperlinks included in the representations of returned resources.

Is HATEOAS RESTful?

HATEOAS stands for Hypermedia as the Engine of Application State and it is a component of RESTful API architecture and design.

How do you implement HATEOAS in REST spring boot?

To implement HATEOAS, we would need to include related resources in the response. Instead of Student we use a return type of EntityModel<Student> . EntityModel is a simple class wrapping a domain object and allows adding links to it. We create a new resource.


1 Answers

I would suggest to throw away swagger and use a restclient like Postman. Postman makes the links provided by spring-hateoas clickable, so you can navigate through the API pretty quickly. If you want to provide some additional information/documentation, you can save those requests into a request collection in Postman and export it for distribution. After I have tried several documentation tools for rest apis, including raml, swagger, apiary and finally Postman-collections in combination with hateaos, I have found the latter to be the one I am most satisfied with.

like image 179
Thomas Eizinger Avatar answered Dec 13 '22 04:12

Thomas Eizinger