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

feat: support setting http response status in functions #1304

Merged
merged 1 commit into from
Nov 21, 2023

Conversation

jonbretman
Copy link
Member

This makes it possible to set the HTTP response status from a function. This only has an effect on the HTTP JSON API, for GraphQL and JSON RPC the response status will always be 200.

Simple example

import { MyFunction, permissions } from "@teamkeel/sdk";

export default MyFunction(async (ctx) => {
  permissions.allow();

  const { response } = ctx;
  response.headers.set("Location", "https://some.url");
  response.status = 301;

  return null;
});

Request Headers

In this change I've also dropped the RequestHeaders class as I don't think it's necessary. Instead I've updated the types to be a Headers object with the mutating methods dropped.

@jonbretman jonbretman requested a review from a team November 17, 2023 16:33
@TejasQ
Copy link
Contributor

TejasQ commented Nov 17, 2023

Great! Let’s add this to the docs.

@jonbretman
Copy link
Member Author

Great! Let’s add this to the docs.

Yep I'll get a docs PR together to go with this.

has(name: string): boolean;
};
// Request headers cannot be mutated, so remove any methods that mutate
export type RequestHeaders = Omit<Headers, "append" | "delete" | "set">;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@jonbretman jonbretman merged commit dc800e9 into main Nov 21, 2023
10 checks passed
@jonbretman jonbretman deleted the functions-http branch November 21, 2023 10:31
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.

3 participants