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

Custom Body Parsers #353

Merged
merged 5 commits into from
Mar 21, 2024
Merged

Custom Body Parsers #353

merged 5 commits into from
Mar 21, 2024

Conversation

kraftp
Copy link
Contributor

@kraftp kraftp commented Mar 21, 2024

PR adding support for custom body parsers through the @KoaBodyParser class decorator. If set, this overrides the default body parser for all endpoints in its class.

Example:

  @KoaBodyParser(bodyParser({
    extendTypes: {
      json: ["application/json", "application/custom-content-type"],
    },
    encoding: "utf-8"
  }))
  class TestEndpoints {
...
}

Addresses issue #350

src/dbos-runtime/runtime.ts Outdated Show resolved Hide resolved
Comment on lines 80 to 84
test("post-test-custom-body", async () => {
const response = await request(testRuntime.getHandlersCallback()).post("/testpost").set('Content-Type', 'application/custom-content-type').send(JSON.stringify({ name: "alice" }));
expect(response.statusCode).toBe(200);
expect(response.text).toBe("hello alice");
});
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you also check the path with an ignored content type?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added, but it's more a test of Koa than of us

@kraftp kraftp merged commit d916594 into main Mar 21, 2024
2 checks passed
@kraftp kraftp deleted the kraftp/custom-body-parser branch March 21, 2024 17:58
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.

None yet

2 participants