@@ -15,7 +15,7 @@ const PayloadMethods: HTTPMethod[] = ['PATCH', 'POST', 'PUT', 'DELETE']
1515 *
1616 * @return {String|Buffer } Encoded raw string or raw Buffer of the body
1717 */
18- export function useRawBody ( event : CompatibilityEvent , encoding : Encoding = 'utf-8' ) : Encoding extends false ? Buffer : Promise < string | Buffer > {
18+ export function readRawBody ( event : CompatibilityEvent , encoding : Encoding = 'utf-8' ) : Encoding extends false ? Buffer : Promise < string | Buffer > {
1919 // Ensure using correct HTTP method before attempt to read payload
2020 assertMethod ( event , PayloadMethods )
2121
@@ -40,6 +40,9 @@ export function useRawBody (event: CompatibilityEvent, encoding: Encoding = 'utf
4040 return encoding ? promise . then ( buff => buff . toString ( encoding ) ) : promise
4141}
4242
43+ /** @deprecated Use `h3.readRawBody` */
44+ export const useRawBody = readRawBody
45+
4346/**
4447 * Reads request body and try to safely parse using [destr](https://github.com/unjs/destr)
4548 * @param event {CompatibilityEvent} H3 event or req passed by h3 handler
@@ -51,13 +54,13 @@ export function useRawBody (event: CompatibilityEvent, encoding: Encoding = 'utf
5154 * const body = await useBody(req)
5255 * ```
5356 */
54- export async function useBody < T = any > ( event : CompatibilityEvent ) : Promise < T > {
57+ export async function readBody < T = any > ( event : CompatibilityEvent ) : Promise < T > {
5558 if ( ParsedBodySymbol in event . req ) {
5659 return ( event . req as any ) [ ParsedBodySymbol ]
5760 }
5861
5962 // TODO: Handle buffer
60- const body = await useRawBody ( event ) as string
63+ const body = await readRawBody ( event ) as string
6164
6265 if ( event . req . headers [ 'content-type' ] === 'application/x-www-form-urlencoded' ) {
6366 const parsedForm = Object . fromEntries ( new URLSearchParams ( body ) )
@@ -68,3 +71,6 @@ export async function useBody<T=any> (event: CompatibilityEvent): Promise<T> {
6871 ( event . req as any ) [ ParsedBodySymbol ] = json
6972 return json
7073}
74+
75+ /** @deprecated Use `h3.readBody` */
76+ export const useBody = readBody
0 commit comments