Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default API #147

Open
jyecusch opened this issue Nov 20, 2022 · 1 comment
Open

Default API #147

jyecusch opened this issue Nov 20, 2022 · 1 comment
Assignees
Labels
enhancement New feature or request

Comments

@jyecusch
Copy link
Member

jyecusch commented Nov 20, 2022

Feature Request

Suggestion

Many applications only include a single API gateway, particularly when developers are learning the framework. To make this use case easier let's expose a 'default' API to reduce the need to create one in every app.

Functions would change from this:

import { api } from "@nitric/sdk";

const helloApi = api('main');

helloApi.get("/hello/:name", async (ctx) => {
    const { name } = ctx.req.params;
    ctx.res.body = `Hello ${name}`;
});

To this:

import { api } from "@nitric/sdk";

api.get("/hello/:name", async (ctx) => {
    const { name } = ctx.req.params;
    ctx.res.body = `Hello ${name}`;
});

Then, creating additional APIs could be performed by calling the api object (same as today):

const main = api('main');

Alternatively, if that's confusing or not possible we could add a new method, e.g.:

const main = api.new('main');

Note: this would be a breaking change.

Value

Should be less confusing for developers new to the framework and requires less code for the majority of projects that will only have a single API.

@jyecusch jyecusch added the enhancement New feature or request label Nov 20, 2022
@tjholm tjholm self-assigned this Jan 9, 2023
@tjholm
Copy link
Member

tjholm commented Jan 9, 2023

One thing that needs to be considered here is securing the default API.

This is currently defined upon API creation, as it needs to be defined at the top level of the API.

Currently we do:

import { api, jwt } from "@nitric/sdk";

const publicApi = api('public', {
  securityDefinitions: {
     'user': jwt({
        issuer: "example...",
        audiences: [],
     })
  }
});

We would need a way to define this for the default api as well.

something like

import { api } from "@nitric/sdk";

api.withSecurity(...)

Also need to somehow invalidate the make cache or force a re-application or delay creation of the API resource.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants