winglang / winglang/wing

cloud.Api catch-all route handler

Open
#3,983 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

✨ enhancement 🎨 sdk
Dominant language
TypeScript
Stars
5.4k
Forks
215
Avg merge
2h 9m
Merged PRs (30d)
27

Description

Feature Spec

A preflight API for running inflight code that should run on all uncaught routes of a cloud.Api:

bring cloud;

let api = new cloud.Api();

api.get("/users/*", inflight (req) => { /* ... */ });
api.get("*", inflight (req) => { /* ... */ });

Since req: cloud.ApiRequest includes path as a field, the inflight function can perform custom logic based on the actual route the user passed.

Related to https://github.com/winglang/wing/pull/3973, https://github.com/winglang/wing/issues/1848

Use Cases

Specifying custom responses for when a request doesn't match any of the other routes you've specified on your cloud.Api.

This kind of capability is available in other frameworks like Express.js using the "*" syntax (see examples here) and SST using the "{proxy+}" path variable (docs).

Implementation Notes

No response

Component

SDK

Community Notes
  • Please vote by adding a 👍 reaction to the issue to help us prioritize.
  • If you are interested to work on this issue, please leave a comment.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the cloud.Api SDK entry point and inspect how routes are registered and how unmatched requests are handled. The change is complete when an uncaught route can invoke the catch-all handler and the handler can use req.path to choose a response; check the existing API tests if available.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
api, backend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.