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
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
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.
sg 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
npm 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 contains a standard mkdocs project, which can be edited using the same tools and format as the main Repository Documentation.
In a nutshell:
- Clone this project into a working directory (which you probably already have).
- Edit the Markdown files in the
docs/docsdirectory. - To run
mkdocslocally and preview your work:Docs will be accessible at http://USER_PREFIX.dev.rdc.library.northwestern.edu:8000/cd docs python -m venv ./.venv pip install -r requirements.txt sg open all 8000 mkdocs serve -a 0.0.0.0:8000
We also maintain an OpenAPI Specification under the docs directory in spec/openapi.yaml. When mkdocs is running, the Swagger UI can be found at http://USER_PREFIX.dev.rdc.library.northwestern.edu:8000/spec/openapi.html. Like the rest of the documentation, changes to the YAML will be immediately visible in the browser.
The existing spec files (openapi.yaml and 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.
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.
openapi.html renders the Swagger UI directly from the unmodified openapi.yaml. 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:
npm 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).