Skip to content

Get

Get allows you to retrieve Items by one of their full key paths. If no Item exists at that key path, nothing is returned. Like Put, Get supports batch requests of up to 50 key paths at a time, returning all the items that exist.

In order to Get an Item you must know one of its key paths, which were defined as part of the Item Type’s schema. Each SDK contains some helpers to build key paths.

Clients automatically parse the returned Items into typed objects, though depending on the language you may have different methods for checking which type an Item is.

For this example we’ll use the schema defined in Example: Movies Schema, which declares Movie as an Item Type with the key path /movies-:id.

15 collapsed lines
package main
import (
"context"
"fmt"
"os"
"slices"
"strconv"
"time"
"github.com/StatelyCloud/go-sdk/stately"
// This is the code you generated from schema
"github.com/StatelyCloud/stately/go-sdk-sample/schema"
)
func sampleGet(
ctx context.Context,
client stately.Client,
movieID []byte,
) (*schema.Movie, error) {
item, err := client.Get(
ctx,
// Construct the key path for the movie
"/movie-"+stately.ToKeyID(movieID),
)
if err != nil {
return nil, err
}
if item == nil { // Item not found
return nil, nil
}
if movie, ok := item.(*schema.Movie); ok {
return movie, nil
}
return nil, fmt.Errorf("item is not a Movie")
}
item, err := client.WithAllowStale(true).Get(
ctx,
"/movie-"+stately.ToKeyID(movieID),
)