当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript request-promise-native.default方法代码示例

本文整理汇总了TypeScript中request-promise-native.default方法的典型用法代码示例。如果您正苦于以下问题:TypeScript request-promise-native.default方法的具体用法?TypeScript request-promise-native.default怎么用?TypeScript request-promise-native.default使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在request-promise-native的用法示例。


在下文中一共展示了request-promise-native.default方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: switch

  private _request<T = any>(
    httpMethod: string,
    url: string,
    params: any,
    token: Token | string | undefined,
  ): Promise<T> {
    const header = this.authenticator.getHeader(token);
    const options: HTTPRequest = {
      method: httpMethod,
      url,
      headers: header,
      json: true,
      resolveWithFullResponse: true,
      simple: false,
    };

    switch (httpMethod) {
      case 'POST':
      case 'PUT':
        options.body = params;
        break;
      default:
        options.qs = params;
    }

    return request(options).then(response => {
      if (response.statusCode < 200 || response.statusCode >= 300) {
        return Promise.reject(new Error(JSON.stringify(response.body)));
      }

      return response.body;
    });
  }
开发者ID:wix,项目名称:media-platform-js-sdk,代码行数:33,代码来源:http-client.ts

示例2: startServer

test('Response data can be deduplicated with graphql-deduplicator', async t => {
  const { uri, data: { book } } = await startServer(t)

  const query = `
    query {
      books {
        __typename
        id
        name
        author {
          __typename
          id
          name
          lastName
        }
      }
    }
  `

  const body = await request({
    uri,
    method: 'POST',
    json: true,
    body: { query },
  }).promise()

  const deduplicated = await request({
    uri,
    method: 'POST',
    json: true,
    body: { query },
    headers: {
      'X-GraphQL-Deduplicate': true
    }
  }).promise()

  t.deepEqual(body, {
    data: {
      books: Array(5).fill(book)
    }
  })

  t.deepEqual(deduplicated, {
    data: {
      books: [
        book,
        ...Array(4).fill({
          __typename: book.__typename,
          id: book.id
        })
      ]
    }
  })

  t.deepEqual(body.data, inflate(deduplicated.data))
})
开发者ID:slimui,项目名称:graphql-yoga,代码行数:56,代码来源:index.test.ts

示例3: rpn

http.createServer((req, resp) => {
  if (req.url === '/doodle.png') {
    const x = rpn('http://mysite.com/doodle.png');
    req.pipe(x);
    x.pipe(resp);
  }
});
开发者ID:enlight,项目名称:DefinitelyTyped,代码行数:7,代码来源:request-promise-native-tests.ts

示例4: request

  /**
   * @param {string} url
   * @param {{}} form
   * @param {Token?} token
   */
  postForm<T = any>(
    url: string,
    form:
      | FormData
      | {
          file: UploadFileStream;
          path: string;
          uploadToken: string | null;
        } & Partial<UploadFileRequest>,
    token?: Token | undefined,
  ): Promise<T> {
    const header = this.authenticator.getHeader(token);

    const options = {
      method: 'POST',
      url,
      formData: form,
      headers: header,
      json: true,
    };

    return request(options).then(
      response => {
        if (response.statusCode < 200 || response.statusCode >= 300) {
          return Promise.reject(response.body);
        }

        return response;
      },
      error => {
        return Promise.reject(error);
      },
    );
  }
开发者ID:wix,项目名称:media-platform-js-sdk,代码行数:39,代码来源:http-client.ts

示例5: resolve

	public async resolve(value: any): Promise<IObject> {
		if (value == null) {
			throw new Error('resolvee is null (or undefined)');
		}

		if (typeof value !== 'string') {
			return value;
		}

		if (this.history.has(value)) {
			throw new Error('cannot resolve already resolved one');
		}

		this.history.add(value);

		const object = await request({
			url: value,
			headers: {
				Accept: 'application/activity+json, application/ld+json'
			},
			json: true
		});

		if (object === null || (
			Array.isArray(object['@context']) ?
				!object['@context'].includes('https://www.w3.org/ns/activitystreams') :
				object['@context'] !== 'https://www.w3.org/ns/activitystreams'
		)) {
			log(`invalid response: ${value}`);
			throw new Error('invalid response');
		}

		return object;
	}
开发者ID:ha-dai,项目名称:Misskey,代码行数:34,代码来源:resolver.ts

示例6: httpRequest

    async function httpRequest(args: { path: string, method: string, body?: any, formData?: any, query?: any, json?: boolean }) {
        const options: any = {
            uri: `${Configuration.baseUrl}${args.path}`,
            method: args.method,
            resolveWithFullResponse: true
        };

        if (args.formData) {
            options.formData = args.formData;
        } else if (args.body) {
            options.body = args.body;
        } else if (args.query) {
            options.qs = args.query;
        }

        if (args.json) {
            options.json = true;
        }
        // console.log(options);
        try {
            return await request(options);
        } finally {
            // console.log(`request sent ${options.method} ${options.uri}`);
        }
    }
开发者ID:KnowledgeExpert,项目名称:allure-client,代码行数:25,代码来源:request.ts

示例7:

	return new Promise<null>((resolve, reject) => {
		let params: any = {
			timestamp: tsPost,
			commentTimestamp: tsComment
		};

		let reqPath = path.join('/v1/server/posts', tsPost.toString(), 'comments', tsComment.toString());
		let url = postAuthor + reqPath;

		if(idtoken && sigtoken) {
			params.idToken = idtoken;
			let signature = utils.computeSignature('DELETE', url, params, sigtoken);
			url += '?idToken=' + idtoken
			url += '&signature=' + signature;
		}

		// We'll use HTTP only for localhost
		if(url.indexOf('localhost') < 0 && !commons.settings.forceHttp) url = 'https://' + url;
		else url = 'http://' + url

		log.debug('Requesting DELETE', url);

		request({
			method: 'DELETE',
			uri: url,
			timeout: commons.settings.timeout
		})
		.then((response) => {
			log.debug('Deleted a comment on', postAuthor.toString());
			resolve(response);
		}).catch(reject);
	});
开发者ID:JosephCaillet,项目名称:cozy-vinimay,代码行数:32,代码来源:commentUtils.ts

示例8: getSitemap

 private async getSitemap() {
   try {
     if (helper.isUrl(this.url) && helper.isXml(this.url)) {
       return await request(this.url);
     }
   } catch (error) {
     console.error(`Error on Request Catch : ${error}`);
     throw error;
   }
 }
开发者ID:Marabyte,项目名称:spa-static,代码行数:10,代码来源:urlExtractor.ts

示例9: request

export async function getTrainPredictions(station: Wmata.Station): Promise<Array<Wmata.TrainPrediction>> {
    let options = {
        url: `https://api.wmata.com/StationPrediction.svc/json/GetPrediction/${station.Code}`,
        headers: {
            api_key: wmataApiKey
        },
        json: true
    };
    return request(options)
        .then(response => response.Trains);
};
开发者ID:Swimburger,项目名称:CommuteStatus,代码行数:11,代码来源:wmataApi.ts


注:本文中的request-promise-native.default方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。