Manage the Extended Properties for Resources

You can provide options on how you want  to handle incoming requests for a resource by defining the extended properties for the resource.
lac52
You can provide options on how you want
Layer7 Live API Creator
to handle incoming requests for a resource by defining the extended properties for the resource. You can access these extended properties from request pipelines, response pipelines, event rules, timers, and listeners.
In this article:
3
Define the Extended Properties for a Resource
Prerequisite:
The resource to which you want to define extended properties exists.
Follow these steps:
  1. With your API open, in the Create section, click
    Resources
    .
    A list of resources display.
  2. Select the resource for which you want to define extended properties from the resource list, and then click the
    Extended Properties
    tab.
  3. Enter valid JSON in the code editor, and then save your changes.
    For examples, see the "Examples of How Define the Extended for a Resource" section.
The extended properties for the resource are defined.
Access the Extended Properties for a Resource from your Code
Prerequisite:
You have defined extended properties for the resource that you want to access the extended properties.
You can access the extended properties for a resource from your code. For example, you can access the extended properties for a resource in the code for a request pipeline. The code performs the indicated processing.
For more information about request pipelines, see Pipeline Events.
Access from JavaScript Code
You can access the extended properties for a resource by adding the
SysUtility.getExtendedPropertiesFor()
method to the JavaScript code for your request pipeline, response pipeline, or event rule. For example:
var extProp = SysUtility.getExtendedPropertiesFor(apiVersionName,req.resourceName);
For more information:
Access from Timer Code
Within the code for timers, you can access the extended properties for a resource by adding the
timerUtil.getExtendedPropertiesFor()
method to the JavaScript code for your timer. For example:
var extProp = timerUtil.getExtendedPropertiesFor(apiVersionName,req.resourceName);
For more information:
Access from Listener Code
Within the code for listeners, you can access the extended properties for a resource by adding the
listenerUtil.getExtendedPropertiesFor()
method to the JavaScript code for your listener. For example:
var extProp = listenerUtil.getExtendedPropertiesFor(apiVersionName,req.resourceName);
For more information:
Examples of How to Define the Extended Properties for a Resource
The following examples demonstrate how you can further extend the functionality of your API by defining the extended proprieties for a resource. You access the extended properties for a resource in a request pipeline that performs the processing. The following sections provide examples of how to define the extended properties for a resource.
Example: Persist Payload
When a client calls a resource, you can persist the incoming payload by accessing the extended properties for the resource.
The
Conference Offers
API sample includes the
PartnerPost
resource that includes extended properties. The extended properties for this resource are defined as follows:
{ "PersistTo": "PartnerPostAudit" }
The
ProcessPayloadOnRequest
request pipeline determines which resource to persist the payload by accessing the extended properties for the
PartnerPost
resource.
For more information about this sample API, see Conference Offers and Management API Samples.
Example: Response Manipulation
You can alter the response JSON and you can drive this alteration from the extended properties for a resource. For example, you might indent street, city, and country under an address group.
Example: Define Aliases for Table-Based Resources
When creating table-based resources and you are connected to a NoSQL database (you are using the
MongoDB
data source provider as a data source),
Layer7 Live API Creator
cannot discover the columns within the database. You can define aliases for the collections that the MongoDB database returns using extended properties.
Consider a table-based resource with the following response for a GET request:
[
{
"_id": {
"$oid": "51df07b094c6acd67e492f41"
},
"name": {
"first": "John",
"last": "McCarthy"
},
"birth": {
"$date": -1335729600000
},
"death": {
"$date": 1324702800000
},
"contribs": [
"Lisp",
"Artificial Intelligence",
"ALGOL"
],
"awards": [
{
"award": "Turing Award",
"year": 1971,
"by": "ACM"
},
{
"award": "Kyoto Prize",
"year": 1988,
"by": "Inamori Foundation"
},
{
"award": "National Medal of Science",
"year": 1990,
"by": "National Science Foundation"
}
],
"@metadata": {
"href": "http://localhost:8080/rest/default/mvzvx/v1/TestMongoResource/51df07b094c6acd67e492f41"
}
}
]
The following example shows how you can alter this response by aliasing the
name
and the
year
attributes to
nombre
and
año
respectively by way of defined extended properties for the resource:
{
"alias_attributes" : [
{
"attribute" : "$.[0].name",
"alias":"nombre"
},
{
"attribute" : "$.[0].awards.[*].year",
"alias": "año"
}
]
}
For responses that contain arrays, use the
<attribute-name>.[<index>]
syntax, where
<index>
is the array index. To denote all the elements of an array, use the
<attribute-name>.[*]
syntax.
Example: Exclude Attributes for Table-Based Resources
When creating table-based resources and you are connected to a NoSQL database (you are using the
MongoDB
data source provider as a data source),
Layer7 Live API Creator
cannot discover the columns within the database. You can exclude attributes for the collections that the MongoDB database returns using extended properties.
Consider a table-based resource with the following response for a GET request:
[
{
"_id": {
"$oid": "51df07b094c6acd67e492f41"
},
"name": {
"first": "John",
"last": "McCarthy"
},
"birth": {
"$date": -1335729600000
},
"death": {
"$date": 1324702800000
},
"contribs": [
"Lisp",
"Artificial Intelligence",
"ALGOL"
],
"awards": [
{
"award": "Turing Award",
"year": 1971,
"by": "ACM"
},
{
"award": "Kyoto Prize",
"year": 1988,
"by": "Inamori Foundation"
},
{
"award": "National Medal of Science",
"year": 1990,
"by": "National Science Foundation"
}
],
"@metadata": {
}
}
]
The following example shows how you can alter this response by excluding the attributes
birth
and
death
by way of defined extended properties for the resource:
{
"exclude_attribute_names":["$.[0].birth","$.[0].death"]
}
For responses that contain arrays, use the
<attribute-name>.[<index>]
syntax, where
<index>
is the array index. To denote all the elements of an array, use the
<attribute-name>.[*]
syntax.