How to use the @phenyl/http-rules.encodeRequest function in @phenyl/http-rules

To help you get started, we’ve selected a few @phenyl/http-rules examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github phenyl / phenyl / modules / http-client / src / index.ts View on Github external
>(
    reqData: RequestDataWithTypeMapForResponse
  ): Promise | ErrorResponseData> {
    // TODO: use HandlerRequest Type instead of Promise
    const { method, headers, path, qsParams, body } = encodeRequest(reqData);
    const qs = stringifyQsParams(qsParams);
    const url = `${this.url}${this.modifyPath(path)}${qs}`;
    const response = await fetch(
      url,
      // @ts-ignore incompatible fetch type and EncodedHttpRequest
      { method, headers, body }
    ).catch((e: Error) => {
      throw createLocalError(e, "NetworkFailed");
    });
    const encodedResponse = {
      body: await response.json(),
      statusCode: response.status,
      headers: response.headers
    }; // FIXME: headers from polyfilled fetch don't implement Headers API.
    // @ts-ignore http-client will not receive any types beyond this point
    return decodeResponse(encodedResponse);

@phenyl/http-rules

(Almost internal) Set of rules that translates HTTP Request/Response into Phenyl RequestData/ResponseData.

Apache-2.0
Latest version published 2 years ago

Package Health Score

57 / 100
Full package analysis

Similar packages