HTTP Datasource Configuration
Styra Load's support for periodically pulling in data from any HTTP services makes it possible to always have a snapshot of remote data available for policy evaluations in Styra Load.
Example Configuration
The HTTP integration is provided via the data
plugin, and needs to be enabled in Load's configuration.
load-conf.yaml (minimal)
plugins:
data:
http.users:
type: http
url: https://internal.example.com/api/users
With this minimal configuration, Styra Load will pull the http.users
information
- retrieved via
GET
, - every 30 seconds,
- sending no request body,
- following redirects.
If the HTTP response contains an ETag
header, it is sent on subsequent requests via If-None-Match
.
Any reponses with status 304 (Not Modified) will not cause data updates.
All of this can be configured using an advanced configuration:
load-conf-advanced.yaml
plugins:
data:
http.users:
type: http
url: https://internal.example.com/api/users
method: POST # default: GET
body: '{"count": 1000}' # default: no body
file: /some/file # alternatively, read request body from a file on disk (default: none)
timeout: "10s" # default: no timeout
polling_interval: "20s" # default: 30s, minimum: 10s
follow_redirects: false # default: true
headers:
Authorization: Bearer XYZ
other-header: # multiple values are supported
- value 1
- value 2
With a config like this, Styra Load will retrieve the document with the specified HTTP request, and attempt to parse as any of:
- XML
- YAML
- JSON
The result will then be available to all policy evaluations under data.http.users
.
Example Call
If the referenced HTTP endpoint responds with the following JSON document,
[
{"username": "alice", "roles": ["admin"]},
{"username": "bob", "roles": []},
{"username": "catherine", "roles": ["viewer"]}
]
then Styra Load's data.http.users
will look like this:
$ curl 'http://127.0.0.1:8181/v1/data/http/users?pretty'
{
"result": [
{
"roles": [
"admin"
],
"username": "alice"
},
{
"roles": [],
"username": "bob"
},
{
"roles": [
"viewer"
],
"username": "catherine"
}
]
}
The key below data
in the configuration (http.users
in the example) can be anything you want,
and determines where the retrieved document will be found in Styra Load's data
hierarchy.