In this blog, we will see how Swagger UI can be generated with Akka HTTP.
Before digging into it further, you can read more about Swagger UI from here and Akka HTTP from here.
Swagger allows developers to effectively interact and try out each and every route that your application exposes and it automatically generates UI from the Swagger specification. The visual documentation makes it easy for developers and clients to interact with the application.
Firstly, we need to add swagger-akka–http dependency in our application’s build.sbt.
"com.github.swagger-akka-http" % "swagger-akka-http_2.11" % "0.14.0"
The Swagger.scala contains a
routes
property which can be concatenated along with existing akka-http routes.<baseUrl>/<specPath>/<resourcePath>
with the specified apiVersion
, swaggerVersion
and resource listing.
Akka-Http routing provides a way to concatenate various HTTP routes which are composed of one or more level of directives that narrows down to handle each specific request.
Adding Swagger UI to your site is quite easy, you just need to drop the static site files into the resources directory of your project.
getFromResourceDirectory("swagger-ui")
Add swagger routes with other routes and bind the routes to a port to start:
You can find the source code here.
Hope you find this blog helpful, Happy Blogging!