Skip to content

feat: support nested routes and configurable stage in SecureRestApi#1720

Merged
toddhainsworth merged 1 commit into
mainfrom
fix/secure-rest-api-nested-routes
Jun 30, 2026
Merged

feat: support nested routes and configurable stage in SecureRestApi#1720
toddhainsworth merged 1 commit into
mainfrom
fix/secure-rest-api-nested-routes

Conversation

@toddhainsworth

@toddhainsworth toddhainsworth commented Jun 29, 2026

Copy link
Copy Markdown
Member

Summary

Two changes to @aligent/cdk-secure-rest-api (released together as a minor):

Nested route paths

The routes helper only worked for single-segment paths. Any path with more than one segment (e.g. rewards/accounts/{accountId}/redeem) threw ResourceSPathPartOnly at synth time, because the construct passed the entire path to IResource.addResource, which only accepts a single path part. Swapped to IResource.resourceForPath, which splits on /, creates intermediate resources, and is idempotent for shared prefixes. The leading-slash strip is preserved for backwards compatibility.

Configurable deployment stage (requested by Kai)

The stage name was always prod (CDK's default). Added a deployOptions?: StageOptions prop passed straight through to the underlying RestApi, so callers can set stageName (and any other stage settings — logging, tracing, etc.). Defaults to the CDK prod stage when omitted.

new SecureRestApi(this, 'Api', {
  apiName: 'my-api',
  deployOptions: { stageName: 'staging' },
  routes: [...],
});

Changes

  • lib/secure-rest-api.tsresourceForPath; new deployOptions prop
  • Tests (17 total): nested route method registration, intermediate resource creation, shared-prefix resolution (shared parent created once + both leaf methods registered), custom stage name, default prod stage
  • README — nested-path + stage-name features, examples, reference entries
  • Changeset (minor)

Testing

  • yarn nx test secure-rest-api — 17/17 pass
  • yarn nx lint secure-rest-api — clean

@toddhainsworth toddhainsworth marked this pull request as ready for review June 29, 2026 23:52
@toddhainsworth toddhainsworth requested a review from a team as a code owner June 29, 2026 23:52
@kai-nguyen-aligent

Copy link
Copy Markdown
Contributor

haha, you beat me on this, @toddhainsworth I have this in my personal kanban too. Could you please also support deployOptions: { stageName } so we can set API gateway stageName? At the moment, it's always prod.

Use IResource.resourceForPath instead of addResource so multi-segment
route paths create their intermediate resources rather than throwing
ResourceSPathPartOnly at synth time. Routes sharing a prefix resolve
idempotently.

Add a deployOptions prop (CDK StageOptions) so the deployed stage name
and other stage settings are configurable; defaults to the CDK prod
stage.

Add tests for nested routes, intermediate resource creation,
shared-prefix resolution, and custom/default stage name; update README
and changeset (minor).
@toddhainsworth toddhainsworth force-pushed the fix/secure-rest-api-nested-routes branch from 24b3357 to 2649bf8 Compare June 30, 2026 00:12
@toddhainsworth

Copy link
Copy Markdown
Member Author

haha, you beat me on this, @toddhainsworth I have this in my personal kanban too. Could you please also support deployOptions: { stageName } so we can set API gateway stageName? At the moment, it's always prod.

☑️

@toddhainsworth toddhainsworth changed the title fix: support nested multi-segment routes in SecureRestApi feat: support nested routes and configurable stage in SecureRestApi Jun 30, 2026

@kai-nguyen-aligent kai-nguyen-aligent left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@toddhainsworth toddhainsworth merged commit 5198087 into main Jun 30, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants