Skip to main content
Version: 1.13.0

ObjectStore.prototype.get

get(): string

Gets the value associated with the key key in the Object store.

Syntax

get(key)

Parameters

  • key : string
    • The key to retrieve from within the Object-store.

Return value

If the key does not exist in the Object store, this returns a Promise which resolves with null.

If the key does exist in the Object store, this returns a Promise which resolves with an ObjectStoreEntry.

Description

Send the given message, converted to a string, to this ObjectStore instance's endpoint.

The get() method requires its this value to be a ObjectStore object.

If the this value does not inherit from ObjectStore.prototype, a TypeError is thrown.

Exceptions

  • TypeError
    • If the provided key:
      • Is any of the strings "", ".", or ".."
      • Starts with the string ".well-known/acme-challenge/"
      • Contains any of the characters "#?*[]\n\r"
      • Is longer than 1024 characters

Examples

In this example we connect to an Object Store named 'files' and save an entry to the store under the key 'hello' and then read back the value and return it to the client.

/// <reference types="@fastly/js-compute" />

import { ObjectStore } from "fastly:object-store";

async function app(event) {
const files = new ObjectStore('files')

await files.put('hello', 'world')

const entry = await files.get('hello')

return new Response(await entry.text())
}

addEventListener("fetch", (event) => event.respondWith(app(event)))