node-fetch#BodyInit TypeScript Examples

The following examples show how to use node-fetch#BodyInit. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: QBittorrent.ts    From cross-seed with Apache License 2.0 6 votes vote down vote up
private async request(
		path: string,
		body: BodyInit,
		headers: Record<string, string> = {},
		retries = 1
	): Promise<string> {
		logger.verbose({
			label: Label.QBITTORRENT,
			message: `Making request to ${path} with body ${body.toString()}`,
		});
		const { origin, pathname } = this.url;
		const response = await fetch(`${origin}${pathname}${path}`, {
			method: "post",
			headers: { Cookie: this.cookie, ...headers },
			body,
		});
		if (response.status === 403 && retries > 0) {
			logger.verbose({
				label: Label.QBITTORRENT,
				message: "received 403 from API. Logging in again and retrying",
			});
			await this.login();
			return this.request(path, body, headers, retries - 1);
		}
		return response.text();
	}
Example #2
Source File: putCustomer.ts    From stellar-anchor-tests with Apache License 2.0 6 votes vote down vote up
requiresJwt: Test = {
  assertion: "requires a SEP-10 JWT",
  sep: 12,
  group: putCustomerGroup,
  dependencies: [hasKycServerUrl],
  context: {
    expects: {
      kycServerUrl: undefined,
    },
    provides: {},
  },
  failureModes: genericFailures,
  async run(config: Config): Promise<Result> {
    const result: Result = { networkCalls: [] };
    const customerValues = getCreateCustomer(config);
    if (!customerValues) {
      throw new Error(
        "SEP-12 configuration data is missing, expected a key within the " +
          "'customers' object matching the value assigned to 'createCustomer'",
      );
    }
    const putCustomerCall: NetworkCall = {
      request: new Request(this.context.expects.kycServerUrl + "/customer", {
        method: "PUT",
        body: customerValues as BodyInit,
      }),
    };
    result.networkCalls.push(putCustomerCall);
    await makeRequest(putCustomerCall, [401, 403], result);
    return result;
  },
}