DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
Securing Your Software Supply Chain with JFrog and Azure
Register Today

Trending

  • How To Use Geo-Partitioning to Comply With Data Regulations and Deliver Low Latency Globally
  • Seven Steps To Deploy Kedro Pipelines on Amazon EMR
  • Revolutionizing Algorithmic Trading: The Power of Reinforcement Learning
  • Constructing Real-Time Analytics: Fundamental Components and Architectural Framework — Part 2

Trending

  • How To Use Geo-Partitioning to Comply With Data Regulations and Deliver Low Latency Globally
  • Seven Steps To Deploy Kedro Pipelines on Amazon EMR
  • Revolutionizing Algorithmic Trading: The Power of Reinforcement Learning
  • Constructing Real-Time Analytics: Fundamental Components and Architectural Framework — Part 2
  1. DZone
  2. Software Design and Architecture
  3. Integration
  4. Easy REST Endpoints with Apache Camel 2.14

Easy REST Endpoints with Apache Camel 2.14

Christian Posta user avatar by
Christian Posta
·
Oct. 16, 14 · Interview
Like (1)
Save
Tweet
Share
28.53K Views

Join the DZone community and get the full member experience.

Join For Free

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?

All right... 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:

        rest("/user").description("User rest service")
            .consumes("application/json").produces("application/json")

            .get("/{id}").description("Find user by id").outType(User.class)
                .to("bean:userService?method=getUser(${header.id})")

            .put().description("Updates or create a user").type(User.class)
                .to("bean:userService?method=updateUser")

            .get("/findAll").description("Find all users").outTypeList(User.class)
                .to("bean:userService?method=listUsers");

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:

        restConfiguration().component("jetty")
            .bindingMode(RestBindingMode.json)
            .dataFormatProperty("prettyPrint", "true")
            .port(8080);

Or this in your Spring context XML:

<camelContext>
  ...
  <restConfiguration bindingMode="auto" component="jetty" port="8080"/>  
  ...
</camelContext>

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.

REST Web Protocols Apache Camel

Published at DZone with permission of Christian Posta, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Trending

  • How To Use Geo-Partitioning to Comply With Data Regulations and Deliver Low Latency Globally
  • Seven Steps To Deploy Kedro Pipelines on Amazon EMR
  • Revolutionizing Algorithmic Trading: The Power of Reinforcement Learning
  • Constructing Real-Time Analytics: Fundamental Components and Architectural Framework — Part 2

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com

Let's be friends: