Domino & REST: Consuming JSON

Consuming JSON is as easy as pie: Just create a new method to the RestApiServlet,  add a @POST annotation, and declare the object you want to the parameters of the method:

    public Response postHelloWorld(HelloWorld helloWorld) {
        return Response.ok(helloWorld, MediaType.APPLICATION_JSON).build();

In this example we are using the same URI „/helloworld/„; because we now are using another HTTP method, there is no conflict between the two methods.

Have a look at the parameter of the postHelloWorld method: It is the HelloWorld class which now instantiated and filled automatically from the POSTed JSON data! We can access the object in Java, and in this short example the result is directly returned back in the response.

If we now send a JSON request with a „message“ field…

curl -i -X POST -d "{\"message\": \"foo\"}" \ 
    -H "Content-Type: application/json" \

… the response contains the message we have posted:

Dieser Beitrag wurde unter Apache Wink, Jackson, Java, JEE, REST abgelegt und mit , , , , , verschlagwortet. Setze ein Lesezeichen auf den Permalink.

1 Antwort zu Domino & REST: Consuming JSON

  1. Ketil Hjerpaasen sagt:

    So good you blog about this. It is an excellent way of using an osgi-plugin to serve dominodata as REST.

    I have used this approach for over a year now and it is very easy to maintain and expand. I use it with a lot of integration projects between domino and other systems. I started with an example made by Tony Samples and built my own version of it.

    I had a problem with settings when I deployed the application, so I have put it in front of a domino db that holds configuration settings. That way I was abele to deploy the same code on the development, test and production environment.
    When I put it in front of the db I was also able to use the standard domino authentication as well.
    CORS is built in with a filter, the same with gzip and to see when the plugin starts and stops.

    But the real killer feature was to document the REST api with swagger. I managed to integrated swagger UI and the Validator Badge into it.
    That made it a real winner.

    Now we have a really fast REST api that serves a lot of other systems with domino data. We even stream files.

    Like your blog and have read it a lot over the years.

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.