Skip to content

In the types, require using $.response to build a response.#1930

Open
pmcelhaney wants to merge 1 commit intomainfrom
require-response-builder
Open

In the types, require using $.response to build a response.#1930
pmcelhaney wants to merge 1 commit intomainfrom
require-response-builder

Conversation

@pmcelhaney
Copy link
Copy Markdown
Collaborator

At the type level, require operation handlers to use $.response.

This no longer type checks:

export const GET: HTTP_GET = () => {
  return "hello world";
};

And neither does this:

export const GET: HTTP_GET = () => {
  return {
    status: 200, 
    body: "hello world"
  };
};

Use the response builder instead.

export const GET: HTTP_GET = ($) => {
  return $.response[200].json("hello world");
};

The first two examples will still work at runtime, so I'm leaning toward not calling this a breaking change.

In the future this will allow us to change the shape of a response at runtime without breaking changes.

It also pushes agents generating code to use $.response instead of returning an object that just happens to be the right shape.

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.

1 participant