How to use the popsicle/dist/common.createTransport 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
import { Response } from "popsicle/dist/response";

export enum HTTPMethod {
  GET = "GET",
  POST = "POST",
  PUT = "PUT",
  PATCH = "PATCH",
  DELETE = "DELETE",
  HEAD = "HEAD",
  OPTIONS = "OPTIONS",
}

export type methods = "GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "HEAD" | "OPTIONS";

export class Request {
  private readonly transport = Popsicle.createTransport({
    rejectUnauthorized: false, // Need to tell node to ignore bad ssl cert
    type: "text",
  });
  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,
    };