Dictionary.prototype.get
This Class is deprecated, it has been renamed to ConfigStore
and can be imported via import { ConfigStore } from 'fastly:config-store'
The get()
method exists on the ConfigStore
Class.
The get()
method returns the value associated with the provided key in the dictionary. If the provided key does not exist in the Dictionary then this returns null
.
Syntax
get(key)
Parameters
key
: string- The key to retrieve from the dictionary.
Return value
A string
representing the specified Dictionary value or null
if the key does not exist in the Dictionary
Description
Get a value for a key in the dictionary. If the provided key does not exist in the Dictionary then this returns null
.
The get()
method requires its this
value to be a Dictionary
object.
If the this
value does not inherit from Dictionary.prototype
, a TypeError
is thrown.
Exceptions
TypeError
- Thrown if the provided key is longer than 255 in length
- Thrown if the provided key is an empty string
Examples
In this example we have an Edge Dictionary named "animals" and we return the "cat" entry as the response body to the client.
/// <reference types="@fastly/js-compute" />
import { Dictionary } from "fastly:dictionary";
async function app (event) {
const config = new Dictionary('animals');
return new Response(config.get('cat'));
}
addEventListener("fetch", event => event.respondWith(app(event)));