How to use the @phenyl/http-rules.decodeRequest 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 / express / src / index.ts View on Github external
const encodedHttpRequest: EncodedHttpRequest = {
        method,
        headers: headers as EncodedHttpRequest["headers"],
        path,
        qsParams: query
      };
      if (!body) {
        encodedHttpRequest.body = await getRawBody(req, true);
      } else if (typeof body === "object") {
        encodedHttpRequest.parsedBody = body;
      } else {
        encodedHttpRequest.body = body;
      }
      let responseData: GeneralResponseData;
      try {
        const requestData = decodeRequest(encodedHttpRequest);
        responseData = await restApiHandler.handleRequestData(requestData);
      } catch (err) {
        responseData = { type: "error", payload: createServerError(err) };
      }
      res.status(getStatusCode(responseData)).json(responseData);
    };
  }

@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