UNPKG

@chubbyts/chubbyts-api

Version:

[![CI](https://github.com/chubbyts/chubbyts-api/workflows/CI/badge.svg?branch=master)](https://github.com/chubbyts/chubbyts-api/actions?query=workflow%3ACI) [![Coverage Status](https://coveralls.io/repos/github/chubbyts/chubbyts-api/badge.svg?branch=maste

10 lines (9 loc) 436 B
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 }); };