Creating a simple REST service in XPages

Monday, August 28, 2017 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

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?

 Reply to this comment
 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.

 Reply to this comment
 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?

 Reply to this comment
 Link to this comment

Leave a comment right here