nitrictech / nitric

Nitric is a multi-language framework for cloud applications with infrastructure from code.
https://nitric.io
Apache License 2.0
1.27k stars 52 forks source link

Local APIs on ports instead of paths #352

Closed jyecusch closed 1 year ago

jyecusch commented 2 years ago

Feature Request

Suggestion

Locally hosting each HTTP API below a sub-path on the same port, e.g. http://localhost:9001/apis/main has lead to confusion with routing due to the extra context path prefix apis/[api_name]. To remove the confusion, let's separate APIs by ports instead.

To improve the likelyhood that APIs start on the same port on subsequent runs (which makes reusing Postman projects, etc. easier) sort them repeatably and host each on an incrementing port number. I propose starting with port 4000, then incrementing by one if it's not available (repeated until an available port is found).

Value

Better representation of how APIs run when published and less confusing. Also allows reusing test suites between local and cloud with just a host change, no path changes.

raksiv commented 2 years ago

This feature look great, it would make sense to make ports configurable, defaulting to 4000 onwards etc makes alot of sense until you actually want more control.

E.g. When you're testing a local front end you'd want to target a specific port so that you aren't having to always worry about resetting the port config @ runtime.

Maybe a local-override setting in the nitric.yaml, which targets the API name:

nitric-start-config:
    apis:
       my-first-api:
           port: 4000
       my-second-api:
          port: 4001
tjholm commented 1 year ago

deployed to production