The env.json file contains environment variable values for the lambda functions defined in the API for use in local development. You can create an env.json file containing the values to run the API against your dev data by running:
make env.jsonIf the file already exists, it will not be overwritten unless you include -B in the make command.
To start the API in development mode, first make sure you have the correct version of the AWS SAM command line utility installed:
asdf install aws-sam-cliThen run the following command:
make serveThe API will be available at:
https://USER_PREFIX.dev.rdc.library.northwestern.edu:3002- Don't forget to open port 3002 if you want to access it remotely
https://USER_PREFIX.dev.rdc.library.northwestern.edu:3002/searchhttps://USER_PREFIX.dev.rdc.library.northwestern.edu:3002/collections
View supported endpoints Questions? View the production API documentation
The API supports simulated network effects (errors and delays) for local testing via the CHAOS_CONFIG environment variable. If the variable is absent the middleware is disabled entirely.
Set it to an inline JSON array:
export CHAOS_CONFIG='[
{ "pattern": "/works/:id", "effect": "error", "status": 500, "chance": 0.3 },
{ "pattern": "/auth/whoami", "effect": "delay", "ms": 500 },
{ "pattern": "/file-sets/*", "effect": "delay", "ms": [100, 800] }
]'Or set it to the path of a JSON file containing the same array:
export CHAOS_CONFIG=/path/to/chaos.jsonEach rule has a pattern (matched against the request path) and an effect:
| Effect | Fields | Behavior |
|---|---|---|
error |
status (HTTP status code), chance (0–1) |
Returns {"error":"chaos"} with the given status; fires chance * 100% of the time |
delay |
ms (number or [min, max]) |
Pauses for the given number of milliseconds (random within range if a tuple) |
All matching rules are evaluated in order. Delay rules accumulate; an error rule short-circuits the request only when it fires — otherwise evaluation continues to the next rule.
View and edit information about a specific Work in the Index.
- Open a local Meadow instance.
- Find an
idof a Work you'd like to inspect in the API. - View JSON response at
https://USER_PREFIX.dev.rdc.library.northwestern.edu:3002/works/[WORK_ID] - View IIIF Manifest JSON response at
https://USER_PREFIX.dev.rdc.library.northwestern.edu:3002/works/[WORK_ID]?as=iiif
IIIF Presentation responses expose IIIF Content Search 2.0 services for transcription annotations:
- Work manifests include a
SearchService2entry forhttps://USER_PREFIX.dev.rdc.library.northwestern.edu:3002/works/[WORK_ID]/search?as=iiif - File set canvases include a
SearchService2entry forhttps://USER_PREFIX.dev.rdc.library.northwestern.edu:3002/file-sets/[FILE_SET_ID]/search?as=iiif
To search transcription text, include a non-empty q parameter:
curl "https://USER_PREFIX.dev.rdc.library.northwestern.edu:3002/works/[WORK_ID]/search?as=iiif&q=[QUERY]"
curl "https://USER_PREFIX.dev.rdc.library.northwestern.edu:3002/file-sets/[FILE_SET_ID]/search?as=iiif&q=[QUERY]"Both endpoints return a IIIF AnnotationPage whose items target the matching work canvas or file set canvas. Requests without as=iiif or a non-empty q return 400.
For help debugging/inspecting, JavaScript console messages are written to: dc-api-v2/dc-api.log
Develop against changes to the API.
- Before starting the DC app, temporarily change the port number in
dc-nextjs/server.jsfrom default3000to something like3003. - Open the port so it can be accessed in the browser.
sgport open all 3003
- Point to the proxy URL and start DC app (in your
/environment/dc-nextjsshell)
export NEXT_PUBLIC_DCAPI_ENDPOINT=https://USER_PREFIX.dev.rdc.library.northwestern.edu:3002
bun run dev
Access the app in a browser at: https://USER_PREFIX.dev.rdc.library.northwestern.edu:3003/
# From the repo root
cd dc-api-v2
# Start the API + step function and associated lambdas
make start-with-step
# Open a second terminal and create the state machine
make state-machineThere are two ways to deploy a development branch: make deploy and make sync. The differences are:
- Changes:
deploydeploys a static stack, and requires anotherdeployto update it.syncwatches for changes in realtime. - Dependencies:
deployuses theapiDependenciesresource defined in the template for dependencies, whilesyncuses the AWS SAM CLI's built-in development dependency logic.
Either way, the resulting stack will be accessible at https://dcapi-USER_PREFIX.rdc-staging.library.northwestern.edu.
An existing sync stack can be reused by running make sync again, or by running make sync-code to only
sync code changes (no infrastructure/template changes).
Both methods involve a samconfig.USER_PREFIX.yaml file. This file, with default values, can be created by
running (for example):
make samconfig.mbk.yamlThis will create a configuration to stand up the default stacks in both deploy mode (API, AV Download, and Chat) and
sync mode (Chat only). To deploy a different combination of features, specify them using the WITH option:
make samconfig.mbk.yaml WITH=API,DOCSAvailable features are: API, AV_DOWNLOAD, CHAT, and DOCS.
sync mode as every change within /api will take a long time to deploy.
As with the env.json file, make will not overwrite an existing file unless you include -B.
sam delete --stack-name dc-api-USER_PREFIXAPI documentation is automatically regenerated and deployed on pushes to the staging and production branches. The documentation is in two parts:
The docs directory builds a single-page ReDoc site. The prose pages in docs/docs are Markdown, and the build folds them into the spec's info.description so they become the first sections of the sidebar, ahead of the API reference.
In a nutshell:
- Clone this project into a working directory (which you probably already have).
- Edit the Markdown files in the
docs/docsdirectory. - To build the site and preview your work:
Docs will be accessible at http://USER_PREFIX.dev.rdc.library.northwestern.edu:8000/, and the server rebuilds whenever a source file changes.
sgport open all 8000 make serve-docs
The Markdown understands two Material for MkDocs conventions that ReDoc does not: === "Label" tab groups, which become a tabbed code widget, and title="..." on a fence, which becomes a caption. Both are translated at build time by docs/lib/markdown.mjs.
We also maintain an OpenAPI Specification under the docs directory in spec/openapi.yaml. The documentation site renders it with ReDoc; when make serve-docs is running, the API reference is part of the single-page site at http://USER_PREFIX.dev.rdc.library.northwestern.edu:8000/. Like the rest of the documentation, changes to the YAML are picked up by the rebuild watcher and visible on reload.
The existing spec files (openapi.yaml, types.yaml, and data-types.yaml) are the best reference for understanding and updating the spec. It's especially important to understand how openapi.yaml uses the $ref keyword to refer to reusable elements defined in types.yaml, and how types.yaml pulls model schemas from data-types.yaml.
For an in-depth look, or to learn how to define things for which there aren't good examples in our spec, refer to the full OpenAPI documentation.
The build copies the spec files to site/spec/ unmodified, so openapi.yaml, types.yaml, and data-types.yaml stay available to consumers; site/spec/openapi.html is a redirect kept for older links. In addition, the build process generates a JSON copy of the spec using the OpenAPI Generator CLI. In order to make sure the spec is valid before checking it in, run:
bun run validate-specThis check is also part of the CI test workflow, so an invalid spec file will cause the branch to fail CI.
Typescript types for the schemas (Works, Collections, FileSets) are automatically published to the nulib/dcapi-types repo on deploys.
- If a deploy to the
deploy/stagingbranch contains changes to thedocs/docs/spec/data-types.yamlfile, new types are generated and a commit is made to thestagingbranch ofnulib/dcapi. This is intended to be for local testing by NUL devs against the private staging API. - If a deploy to production (
mainbranch) contains changes to thedocs/docs/spec/data-types.yamlfile, new types are generated and a PR is opened into themainbranch ofnulib/dcapi-types. Also, an issue is created innulib/repodev_planning_and_docsto review the PR and publish the types package (manually).
The current API version is maintained in several different project files. To increment the version, use
make version BUMP=<major|minor|patch>
If you don't specify a BUMP value, the command will simply print the current version.