My second REST API

Idea

How about getting the properties of one person? How do we search for a person and return this person’s properties? And for testing, do we have a better solution?

Configuration

Open again the application "My first REST API" in the notes designer, then reopen the groovy configuration document called 'XRest API Routes'.

Copy the code below and paste it below the existing code. This is our second route named 'user' and requires a universal id of a notes document as parameter.

Code for the second REST API
router.GET('user/{id}') {
	strategy(DOCUMENT_BY_UNID) {
		keyVariableName('id')
		databaseName('names.nsf')
	}
	description '<b>Domino Directory -> get one user by its universal ID</b>'
	mapJson 'UNID', json:'unid', type:'STRING', isformula:true, formula:'@Text(@DocumentUniqueID)' 
	mapJson 'FirstName', json:'firstname', type:'STRING'
	mapJson 'LastName', json:'lastname', type:'STRING'
	mapJson 'FullName', json:'fullname', type:'ARRAY_OF_STRING'
	mapJson 'InternetAddress', json:'email', type:'STRING'
	mapJson 'ShortName', json:'shortname', type:'STRING'
	mapJson 'CompanyName', json:'companyname', type:'STRING'
	mapJson 'Department', json:'department', type:'STRING'
	mapJson 'Created', json:'Created', type:'DATETIME', isformula:true, formula:'@Created'
	mapJson 'Modified', json:'Modified', type:'DATETIME', isformula:true, formula:'@Modified'
}

Save and close, build.


Further explanations


Test

To test our routes we switch to the postman program. Download it and get started here:
https://learning.postman.com/docs/getting-started/introduction/

Don’t forget to add a Basic Authentication in postman.


The url to test is now:
http://localhost/rest/myfirst.nsf/xsp/.xrest/user/FBF7A31E216AAA65C12578E9003EEC0E

user

DOCUMENT_BY_UNID

FBF7A31E216AAA65C125.....

Name of the route router.GET('user/{id}')

The name of our strategy

Universal Document ID is the parameter value id

The properties of the requested person record results in a JSON formatted answer:

{
    "firstname": "Tick",
    "unid": "FBF7A31E216AAA65C12578E9003EEC0E",
    "Modified": "2019-08-08T05:36:47+00:00",
    "companyname": "",
    "fullname": [
        "CN=Tick Duck/O=WGCDEV/C=CH",
        "Tick Duck"
    ],
    "department": "",
    "shortname": "TDuck",
    "email": "Tick.Duck@wgcdev.ch",
    "lastname": "Duck",
    "Created": "2011-08-11T11:27:16+00:00"
}


What have we learned?