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

Support for CloudEvents requests #350

Closed
resamaraschi opened this issue Mar 19, 2024 · 3 comments
Closed

Support for CloudEvents requests #350

resamaraschi opened this issue Mar 19, 2024 · 3 comments

Comments

@resamaraschi
Copy link

I am working on an integration of a DBOS app with Dapr runtime. Dapr subpub building block transmits the message as a so called Envelope in the body of POST request with Content-Type header set to application/cloudevents+json" (see 1).

Currently the instantiated koa bodyparser in dbos-sdk, does not provide a way of extending allowed Content-Types, thus the body of HandlerContext.request.body is empty after it was parsed. In other words the DBOS endpoint can only work with request with a Content-Type listed here

Since the current version of dbos-ts relies heavily on http request to trigger a workflow, it would be important to provide more configuration for involved koa components such as bodyparser:

For instance in server.ts

    this.app.use(bodyParser({
        "extendTypes": {
            // will parse application/cloudevents+json type body as a JSON string
            json: ["application/cloudevents+json"],
          }
    }));

Unfortunately I am not a TypeScript developer, otherwise, I would have contributed with a PR. :)

Thanks

@kraftp
Copy link
Member

kraftp commented Mar 21, 2024

Thanks for filing this issue! We now have a PR enabling custom body-parsing middleware: #353

Is this what you had in mind?

@resamaraschi
Copy link
Author

Yes it is. Many thanks :)

kraftp added a commit that referenced this issue 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:

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

Addresses issue #350
@kraftp
Copy link
Member

kraftp commented Mar 21, 2024

Fixed through the @KoaBodyParser decorator in #353, which adds support for fully custom body parsers.

If you want to try it out now, install our preview build: npm i @dbos-inc/dbos-sdk@preview. Otherwise, this will be included in our next release next week.

@kraftp kraftp closed this as completed Mar 21, 2024
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

No branches or pull requests

2 participants