SPEAKER: Hello, and welcome to this episode of the Apigee
Accelerator Series.
In this video, you will learn how to implement and use
property sets in Apigee.
A property set is a custom collection of key-value pairs
that store data.
API proxy and shared flows can retrieve this data
when they execute.
These key-value pairs are stored into a properties file,
as shown on the following example.
In this example, the name of the file is myProps.properties.
And it contains seven key-value pairs.
As an example, foo is a key.
And bar is the value for the foo key.
Typically, you use property sets to store non-expiring data that
shouldn't be hard-coded in your API proxy logic.
You can access property set data anywhere in a proxy
where you can access flow variables.
In the following example, you can
access the value of the foo key using the flow variable
propertyset.myProps.foo.
Some other important things to know about property sets--
first, you can scope a property set
to an API proxy revision or environment
when you create a property set.
You cannot scope a property set to an Apigee organization.
Second, property set files are resource files
of type properties that you can manage through the Apigee
UI or the Apigee API.
Last, but not least, property set files
support the same syntax as Java properties files.
As mentioned in this video, you can
access property sets' variables from the policies where
you can access flow variables, like JavaScript policy,
extract variable policy, assign message policy.
The following example, based on the resource extract
of a JavaScript policy, gets the value of the foo property
from the property set named myProps.
Let me show you how you can deploy
a basic example of a property set on your Apigee
organization.
Let's begin.
Go to the Google Cloud platform and apigee-samples Git repo
and enter the property set sample.
In order to run this sample, you need the following--
an Apigee X instance with access configured
for external traffic.
As a user, you need permissions to deploy an API proxy.
This can be granted to the Apigee org admin
role or the API and developer admin roles.
To deploy the sample, you also need the command line tools
shown here.
If you are using Google Cloud Shell,
these tools are already installed.
We have included a Google Cloud Shell tutorial
that you can simply click to quickly get started.
Now that you're in the Cloud Shell environment,
you can follow along with the step-by-step instructions.
First, make sure you are logged in with the right account.
Then change to the directory for this sample.
To deploy your sample, first open up the env.sh
and set the configuration to reference
your Apigee organization, environment,
and external hostname.
Next, run the included script to deploy your sample
to your Apigee instance.
This might take a minute to complete.
When the script completes, you should see a message
showing the API proxy URL.
Now, run the curl command, and notice the values
in the output.
You should see a JSON payload whose content
has been set based on values extracted from a property set.
Two custom headers have also been set
based on the same property set.
Now that you have seen the API proxy in action,
let's look at how it is configured in Apigee.
You can access the Apigee UI directly
from the Google Cloud Console.
Look for the property set API proxy.
Select the proxy and go to the Develop tab.
You see two policies defined and two resource files
of type properties and JavaScript.
The properties file named myProps contains
keys that are used by the JavaScript and AssignMessage
policies.
First, the JavaScript policy gets two values
from the property set and set these two
values as custom response headers, x-baz and x-note.
Then, an AssignMessage policy uses flow variables
to set a custom payload based on the same property set,
using different keys and values.
The JavaScript and AssignMessage policies
are example on how to use flow variables to get values of keys
defined in a property set.
When you're done with your sample,
you can provide us with your feedback.
And then you can use the cleanup script
to delete the configuration that was
deployed to your organization.
We hope you found this sample useful.
And if you enjoyed the video, please
hit the Like button below.
You can also subscribe to our channel
to see more videos in the Apigee Accelerator series.
If you have questions, please post them
on the Apigee community.
Thanks for watching.