How to use the popsicle/dist/common.request function in popsicle

To help you get started, we’ve selected a few popsicle 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 pact-foundation / pact-js / src / common / request.ts View on Github external
public send(method: HTTPMethod | methods, url: string, body?: string): Promise {
    const opts = {
      body,
      headers: {
        "Content-Type": "application/json",
        "X-Pact-Mock-Service": "true",
      },
      method,
      timeout: 10000,
      transport: this.transport,
      url,
    };

    return Popsicle.request(opts)
      .then((res: Response) => {
        if (res.status >= 200 && res.status < 400) {
          return res.body;
        } else {
          return Promise.reject(res.body);
        }
      });
  }
}