MuleESB / Apache Camel Interview Questions
How do you use the Camel REST DSL to expose and consume REST services?
The REST DSL is a domain-specific language layered on top of Camel HTTP transport components. It describes REST APIs in a declarative verb-and-path style. The underlying HTTP server is pluggable — Undertow, Jetty, Servlet, or Netty — chosen via restConfiguration().
public class OrderRestRoutes extends RouteBuilder {
@Override
public void configure() {
restConfiguration()
.component("undertow").host("0.0.0.0").port(8080);
rest("/api/orders")
.get("/{id}").produces("application/json")
.to("direct:getOrder")
.post("/").consumes("application/json")
.type(OrderRequest.class)
.to("direct:createOrder");
from("direct:getOrder")
.to("sql:SELECT * FROM orders WHERE id = :#${header.id}");
}
}
// Consuming an external REST endpoint:
from("direct:callProducts")
.to("rest:GET:/api/products?host=catalog.internal:8080");REST DSL routes handle JSON/XML binding automatically when a type() class is specified. The rest: component acts as a producer for calling external REST APIs. Use camel-openapi-java to generate an OpenAPI spec from REST DSL definitions. In Spring Boot, auto-configure the REST engine via camel.rest.component=servlet.
Invest now in Acorns!!! 🚀
Join Acorns and get your $5 bonus!
Acorns is a micro-investing app that automatically invests your "spare change" from daily purchases into diversified, expert-built portfolios of ETFs. It is designed for beginners, allowing you to start investing with as little as $5. The service automates saving and investing. Disclosure: I may receive a referral bonus.
Invest now!!! Get Free equity stock (US, UK only)!
Use Robinhood app to invest in stocks. It is safe and secure. Use the Referral link to claim your free stock when you sign up!.
The Robinhood app makes it easy to trade stocks, crypto and more.
Webull! Receive free stock by signing up using the link: Webull signup.
More Related questions...
