Creating a simple REST service in XPages

Monday, August 28, 2017 at 10:18 PM UTC

This evening I encountered this question on twitter:

The answers were clear and so was mine: don't try to mimic XML or something using an Agent. Use a Custom REST Service instead.

The principle is very simple: create an XPage, place a REST service component on it and point it to a custom service bean which you have to create as a Java class. This Java class has to extend the CustomServiceBean class and to incorporate the renderService method which should generate an output. This output nowadays should be a JSON response.

I set up a simple example NSF to demonstrate how this works here





Latest comments to this post

Sean Cull wrote on 10.06.2020, 22:22

+1 for Patrick's question. 

Our use case is that we got a huge data collection in a bean and want to page through it without having to populate the bean again. Is this possible if it was in the application bean ?

Probably a newbie question but if a Domino authenticated user in Angular makes a second API call ( for records 101 - 200 ) can they pull these from a session scope bean ?

Trying to understand how we can page through a large view of Domino FT search results in an Angular front end.

Thanks, Sean

 Link to this comment
Patrick Kwinten wrote on 04.10.2017, 13:17

Yes, I came to such "workaround" myself but I can not directly call a specific method in a Java class?

 Link to this comment
Oliver Busse wrote on 04.10.2017, 12:00

Sure, you can provide a param which tells the service which action to perform. Then the service can call and respond with corresponding code.

 Link to this comment
Patrick Kwinten wrote on 04.10.2017, 09:48

Is it thinkable to have the managed bean serving multiple rest services? in the example 1 rest service equals 1 managed bean. can the rest service not be bound to a method in my managed bean so it is easier to share common code?

 Link to this comment

Leave a comment right here