@chubbyts/chubbyts-api
Version:
[](https://github.com/chubbyts/chubbyts-api/actions?query=workflow%3ACI) [ • 436 B
JavaScript
import { streamToString } from './stream.js';
export const parseRequestBody = async (decoder, request) => {
const contentType = request.attributes.contentType;
if (!contentType) {
throw new Error('Use createContentTypeNegotiationMiddleware to assign request.attributes.contentType.');
}
const encodedBody = await streamToString(request.body);
return decoder.decode(encodedBody, contentType, { request });
};