Reputation: 380
I've only recently started experimenting with the REST control in the latest Xpages Extension library.
I've been able to create a REST control to return the contents of a view: https://www.example.com/RESTApp.nsf/data.xsp/companies
and the fields in a document by passing in the UNID: https://www.example.com/RESTApp.nsf/data.xsp/company/unid/8C4DA14484C699B488257F0800691B2C
Taking this a step further, I would like to create a REST API that can be used by another IT group within my company to access customer data (say based on customer ID). If I have a Domino view with customer data sorted by customer ID, what would my REST control look like if the external group wanted to consume the REST service by passing a customer ID along instead of a UNID?
Would I need to create a custom REST service? Any examples to get me started would be much appreciated.
Thanks,
Dan
Upvotes: 0
Views: 677
Reputation: 20384
It very much depends on how your API should look like to the outside. You have 2 considerations:
?ReadViewEntries&OutputFormat=JSON&RestrictToCategory=customerID
when you categorize your view would be the easiest way to have some (readonly) rest API.
I however would start with a Swagger API definition definition negotiated with the other group. This approach is called "contract first development". Then build a custom bean based REST service. Since you have access to the URL, you can grab the part after your rest name (e.g. data.xsp/company/companyID ).
Use my blog article as starting point.
In a nutshell: your bean needs to extend the CustomServiceBean
. Pretty straightforward.
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.ibm.domino.services.ServiceException;
import com.ibm.domino.services.rest.RestServiceEngine;
import com.ibm.xsp.extlib.component.rest.CustomService;
import com.ibm.xsp.extlib.component.rest.CustomServiceBean;
public class CustomSearchHelper extends CustomServiceBean {
@Override
public void renderService(CustomService service, RestServiceEngine engine) throws ServiceException {
HttpServletRequest request = engine.getHttpRequest();
HttpServletResponse response = engine.getHttpResponse();
response.setHeader("Content-Type", "application/json; charset=UTF-8");
// Your code goes here!
}
}
Let us know how it goes
Upvotes: 0
Reputation: 338
I do think you need to create a custom REST service.
If you are looking for the URL to pass, it would be something like this: http://localhost/jobs10.nsf/TriggerNav.xsp?/hotSheets?rName=Alex
And us something like:
var uriString = facesContext.getExternalContext().getRequest().getRequestURI(); var unidString = @RightBack(uriString, "rNamee/");
to get the parameter you pass. Pass that into your GET, and it should work.
I did a Notesin9 about this, and the link here as the full application. It writes into a nsf, but you can adopt it to
Cheers, Brian
Upvotes: 1