Copyright© 2008-2023 Sitevision AB, all rights reserved.
O
- script objectpublic interface RestAppInvoker<O>
This is a local, server-side, inbound utility to invoke a specific RESTApp of the local site without any outgoing http connections. This utility can be used regardless of the RESTApp allows requests or not! Verb/method restrictions (GET/POST/PUT/DELETE/PATCH) specified for the RESTApp will be respected.
This utility has methods to server-side invoke a specific RESTApp that resides on the same site as this code is executed. Each method requires that a route is specified. Each method also allows for options to be passed to the RESTApp so it can do its job properly. Each method returns an object with the result of the RESTApp invocation.
Node
(of type sv:file, sv:image or sv:temporaryFileNode) if the RESTApp executes
res.sendFile
object
if the RESTApp executes
res.json
string
if the RESTApp executes
res.send
Below is an example of how to use the RestAppInvoker utility to execute a GET on the items route of a RESTApp.
var restAppInvokerFactory = require('RestAppInvokerFactory'),
restApp = restAppInvokerFactory.fromPath('/rest-api/my-rest-app'),
result;
if (restApp) {
result = restApp.get('/items', {count:5});
if (result.statusCode === 200) {
// Handle valid result ...
result.body ...
} else {
// Handle other/error result ...
}
}
Below is an example of how to use the RestAppInvoker utility to execute a POST on the addfile route of a RESTApp.
var restAppInvokerFactory = require('RestAppInvokerFactory'),
restApp = restAppInvokerFactory.fromPath('/rest-api/my-rest-app'),
fileNode,
options,
result;
if (restApp) {
fileNode = ... // Get the JCR file Node (sv:file, sv:image) to pass to the RESTApp
options = {
headers: {
'X-custom-header': 'Custom value'
},
spreadsheet: fileNode,
sendMail: true,
customerId: 'abc123'
};
result = restApp.post('/addfile', options);
if (result.statusCode === 200) {
// Handle valid result ...
result.body ...
} else {
// Handle other/error result ...
}
}
REST siblings note!
RestApi
.
Requester
.
An instance of the Sitevision class implementing this interface can be obtained via a method in
RestAppInvokerFactory
.
Modifier and Type | Method and Description |
---|---|
O |
delete(String aRoute)
Executes DELETE for a route of the RESTApp.
|
O |
delete(String aRoute,
O aOptions)
Executes DELETE with options for a route of the RESTApp.
|
O |
get(String aRoute)
Executes GET for a route of the RESTApp.
|
O |
get(String aRoute,
O aOptions)
Executes GET with options for a route of the RESTApp.
|
O |
patch(String aRoute)
Executes PATCH for a route of the RESTApp.
|
O |
patch(String aRoute,
O aOptions)
Executes PATCH with options for a route of the RESTApp.
|
O |
post(String aRoute)
Executes POST for a route of the RESTApp.
|
O |
post(String aRoute,
O aOptions)
Executes POST with options for a route of the RESTApp.
|
O |
put(String aRoute)
Executes PUT for a route of the RESTApp.
|
O |
put(String aRoute,
O aOptions)
Executes PUT with options for a route of the RESTApp.
|
O get(String aRoute)
REST hint! A get typically indicates a read of something.
aRoute
- a routeget(String, Object)
O get(String aRoute, O aOptions)
REST hint! A get typically indicates a read of something.
aRoute
- a routeaOptions
- a optionsO post(String aRoute)
REST hint! A post typically indicates the creation of something.
aRoute
- a routepost(String, Object)
O post(String aRoute, O aOptions)
REST hint! A post typically indicates the creation of something.
aRoute
- a routeaOptions
- a optionsO put(String aRoute)
REST hint! A put typically indicates an update of something.
aRoute
- a routeput(String, Object)
O put(String aRoute, O aOptions)
REST hint! A put typically indicates an update of something.
aRoute
- a routeaOptions
- a optionsO delete(String aRoute)
REST hint! A delete typically indicates a removal of something.
aRoute
- a routedelete(String, Object)
O delete(String aRoute, O aOptions)
REST hint! A delete typically indicates a removal of something.
aRoute
- a routeaOptions
- a optionsO patch(String aRoute)
REST hint! A patch typically indicates a partial update of something.
aRoute
- a routepatch(String, Object)
O patch(String aRoute, O aOptions)
REST hint! A patch typically indicates a partial update of something.
aRoute
- a routeaOptions
- a optionsSitevision - Portal and Content Management Made Easy
Sitevision is an advanced Java enterprise portal product and a portlet container (JSR 286) that implements Java Content Repository (JSR 283).
Copyright© 2008-2023 Sitevision AB, all rights reserved.