Skip to content

Commit

Permalink
🤖 Merge PR DefinitelyTyped#60411 Added .text() and .json() to respons…
Browse files Browse the repository at this point in the history
…eProvider Request object by @stingare
  • Loading branch information
stingare authored May 20, 2022
1 parent 6326ec1 commit 236a831
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
16 changes: 15 additions & 1 deletion types/akamai-edgeworkers/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,20 @@ declare namespace EW {
readonly cacheKey: CacheKey;
}

interface ReadsBody {
/**
* A promise that reads the body to completion and resolves to a string containing the full
* body decoded as UTF-8, using the replacement character on encoding errors.
*/
text(): Promise<string>;

/**
* A promise that reads the body to completion and resolves to an Object that is the result
* of parsing the body as JSON.
*/
json(): Promise<any>;
}

interface Request {
/**
* The Host header value of the incoming request.
Expand Down Expand Up @@ -240,7 +254,7 @@ declare namespace EW {
}

// responseProvider
interface ResponseProviderRequest extends Request, ReadsHeaders, ReadAllHeader {
interface ResponseProviderRequest extends Request, ReadsHeaders, ReadAllHeader, ReadsBody {
}

interface Destination {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,10 @@ export function responseProvider(request: EW.ResponseProviderRequest) {
// get a specific header and do string operations
const acceptHeader = headers["accept-encoding"];
acceptHeader.forEach(val => val.toUpperCase());

// EW.ResponseProviderRequest.text()
const stringBody = request.text();

// EW.ResponseProviderRequest.json()
const jsonBody = request.json();
}

0 comments on commit 236a831

Please sign in to comment.