SecretStore.prototype.get
▸ get(): string
Gets the value associated with the key key in the Secret store.
Syntax
get(key)
Parameters
key: string- The key to retrieve from within the Secret Store.
Return value
If the key does not exist in the Secret Store, this returns a Promise which resolves with null.
If the key does exist in the Secret Store, this returns a Promise which resolves with an SecretStoreEntry.
Description
Send the given message, converted to a string, to this SecretStore instance's endpoint.
The get() method requires its this value to be a SecretStore object.
If the this value does not inherit from SecretStore.prototype, a TypeError is thrown.
Exceptions
TypeError- If the provided
key:- Is an empty string
- Is longer than 255 characters
- Contains characters other than letters, numbers, dashes (-), underscores (_), and periods (.)
- If the provided
Examples
In this example we connect to a Secret Store named 'secrets' and retrieve a secret named 'cat-api-key' use the value in a Request header.
/// <reference types="@fastly/js-compute" />
import { SecretStore } from "fastly:secret-store";
async function app(event) {
const secrets = new SecretStore('secrets')
const catApiKey = await secrets.get('cat-api-key')
return fetch('/api/cat', {
headers: {
'cat-api-key': catApiKey.plaintext()
}
})
}
addEventListener("fetch", (event) => event.respondWith(app(event)))