Slack Discussion Two of the most commonly used beans when developing a RESTful web service are localization and swagger. Localization allow...
Slack Discussion
Two of the most commonly used beans when developing a RESTful web service are localization and swagger. Localization allows us to translate messages from one language to another by passing accept-language header in the request. While swagger helps us in documenting our REST APIs with the use of annotations.
Let’s see them in action.
First, add the dependency on maven pom file [show the pom file]
Create the localization and swagger configuration, don’t forget to annotate the classes with @Configuration so that Spring will pick them up.
Then create the category controller for testing [show the CategoryController class]
Notice that we use swagger classes to annotate the endpoint and the method. These will be shown the auto-generated documentation later.
[demo http://localhost:8080/swagger-ui.html]
[demo http://localhost:8080/categories/hello in postman]
Two of the most commonly used beans when developing a RESTful web service are localization and swagger. Localization allows us to translate messages from one language to another by passing accept-language header in the request. While swagger helps us in documenting our REST APIs with the use of annotations.
Let’s see them in action.
First, add the dependency on maven pom file [show the pom file]
Create the localization and swagger configuration, don’t forget to annotate the classes with @Configuration so that Spring will pick them up.
Then create the category controller for testing [show the CategoryController class]
Notice that we use swagger classes to annotate the endpoint and the method. These will be shown the auto-generated documentation later.
[demo http://localhost:8080/swagger-ui.html]
[demo http://localhost:8080/categories/hello in postman]
COMMENTS