Christian Posta bio photo

Christian Posta

Field CTO at solo.io, author Istio in Action and Microservices for Java Developers, open-source enthusiast, cloud application development, committer @ Apache, Serverless, Cloud, Integration, Kubernetes, Docker, Istio, Envoy #blogger

Twitter Google+ LinkedIn Github Stackoverflow

Apache Camel has a new release recently, and some of the new features were blogged about by my colleague Claus Ibsen. You really should check out his blog entry and dig into more detail, but one of the features I was looking forward to trying was the new REST DSL.

So what is this new DSL?

Actually, it's an extension to Camel's routing DSL, which is a powerful domain language for declaratively describing integration flows and is available in many flavors. It's pretty awesome, and is a differentiator between integration libraries. If you haven't seen Camel's DSL, you should check it out. Have I mentioned that Camel's DSL is awesome?

k.. back to the REST story here..

Before release 2.14, creating rest endpoints meant using camel-cxfrs which can be difficult to approach for a new user just trying to expose a simple REST endpoint. Actually, it's a very powerful approach to doing contract-first REST design, but I'll leave that for the next blog post. However, in a previous post I did dive into using camel-cxfrs for REST endpoints so you can check it out.

With the 2.14, the DSL has been extended to make it easier to create REST endpoints. For example:

In this example, we can see we use the DSL to define REST endpoints, and it's clear, intuitive and straight forward.

All you have to do is set up the REST engine with this line:

Or this in your Spring context XML:

The cool part is you can use multiple HTTP/servlet engines with this approach, including a micrservices style with embedded jetty (camel-jetty) or through an existing servlet container (camel-servlet). Take a look at the REST DSL documentation for the complete of HTTP/servlet components you can use with this DSL.

Lastly, some might ask, what about documenting the REST endpoint? Eg, WADL?
Well, luckily, the new REST DSL is integrated out of the box with awesome Swagger library and REST documenting engine ! So you can auto document your REST endpoints and have the docs/interface/spec generated for you! Take a look at the camel-swagger documentation and the camel-example-servlet-rest-tomcat example that comes with the distribution to see more.

Give it a try, and let us know (Camel mailing list, comments, stackoverflow, somehow!!!) how it works for you.