winglang / wing

A programming language for the cloud ☁️ A unified programming model, combining infrastructure and runtime code into one language ⚡
https://winglang.io
Other
4.84k stars 189 forks source link

Add ability to add ENV variable across all API routes #6842

Open boyney123 opened 1 month ago

boyney123 commented 1 month ago

Use Case

When defining a Cloud.API we can configure a few props (cors and corsOptions).

When we define routes on the API resource we can also add env to them (see example of GET)

This is a proposal to allow the cloud.Api resource to define these at a high level (when we define the resource itself) through it's (ApiProps). Setting env values here would apply to all routes configured in the API.

Proposed Solution

Allow user to define env variables when creating a new API.

this.api = new cloud.Api({
      env: {
        HELLO: "WORLD"
      }
    }) as "API";

Implementation Notes

No response

Component

No response

Community Notes

eladb commented 1 month ago

@boyney123 What's the use case for passing these environment variables to all api routes?

boyney123 commented 1 month ago

Hmm yeah good question 😅

Mainly usecases if the API (service) is integrating with 3rd party systems (cloud cache, cloud DB etc), and maybe to share these ENV across all routes in the API? S3 urls etc that they all need access too? Or API URLS they all need access too?

I know previously I have done things with SAM using Globals

Now I think about it more I'm unsure if its really required tbh... maybe we should keep this issue see if any users come back in the future and express interest (or not!).