I'm trying to use the Apache Camel REST DSL to create a simple REST API that just is supposed to return a String when called.
However, while the code below was once working, the API seems to have changed
rest().get("/hello-world").produces(MediaType.APPLICATION_JSON_VALUE).route()
.setBody(constant("Welcome to apache camel test ")).endRest();
route() does not exist anymore in Apache Camel 3.17.0
I've also tried
rest("/say")
.get("/hello")
.responseMessage(200, "Hello World");
But this returns an empty String instead of "Hello World"
The only thing that worked so far is by creating an extra route
rest("/say")
.get("/hello")
.to("direct:build-return-message");
from("direct:build-return-message")
.setBody(simple("Hello World"));
But this can't be the preferred way.
How would you now set the response body with the latest API?
While you can no longer define a simple route that returns a string in Rest-DSL you can use camels language component to achieve something similar using constants, simple language or by using a file in resources folder.
It's unfortunate that examples for language-component are quite sparse as it looks like handy tool for bunch of little things.