How to use request-light - 10 common examples

To help you get started, we’ve selected a few request-light 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 redhat-developer / yaml-language-server / src / server.ts View on Github external
function getSchemaStoreMatchingSchemas() {
    return xhr({ url: JSON_SCHEMASTORE_URL }).then(response => {
        const languageSettings = {
            schemas: []
        };

        // Parse the schema store catalog as JSON
        const schemas = JSON.parse(response.responseText);

        for (const schemaIndex in schemas.schemas) {
            const schema = schemas.schemas[schemaIndex];

            if (schema && schema.fileMatch) {
                for (const fileMatch in schema.fileMatch) {
                    const currFileMatch = schema.fileMatch[fileMatch];
                    // If the schema is for files with a YAML extension, save the schema association
                    if (currFileMatch.indexOf('.yml') !== -1 || currFileMatch.indexOf('.yaml') !== -1) {
                        languageSettings.schemas.push({ uri: schema.url, fileMatch: [currFileMatch] });
github microsoft / BotFramework-Composer / Composer / packages / tools / language-servers / language-understanding / src / LUServer.ts View on Github external
protected async resovleSchema(url: string): Promise {
    const uri = URI.parse(url);
    if (uri.scheme === 'file') {
      return new Promise((resolve, reject) => {
        // eslint-disable-next-line security/detect-non-literal-fs-filename
        fs.readFile(uri.fsPath, 'UTF-8', (err, result) => {
          err ? reject('') : resolve(result.toString());
        });
      });
    }
    try {
      const response = await xhr({ url, followRedirects: 5 });
      return response.responseText;
    } catch (error) {
      return Promise.reject(error.responseText || getErrorStatusDescription(error.status) || error.toString());
    }
  }
github microsoft / BotFramework-Composer / Composer / packages / tools / language-servers / language-understanding / src / LUServer.ts View on Github external
protected async resovleSchema(url: string): Promise {
    const uri = URI.parse(url);
    if (uri.scheme === 'file') {
      return new Promise((resolve, reject) => {
        // eslint-disable-next-line security/detect-non-literal-fs-filename
        fs.readFile(uri.fsPath, 'UTF-8', (err, result) => {
          err ? reject('') : resolve(result.toString());
        });
      });
    }
    try {
      const response = await xhr({ url, followRedirects: 5 });
      return response.responseText;
    } catch (error) {
      return Promise.reject(error.responseText || getErrorStatusDescription(error.status) || error.toString());
    }
  }
github microsoft / BotFramework-Composer / Composer / packages / tools / language-servers / lg-language-server / lib / server.js View on Github external
async resovleSchema(url) {
    const uri = vscode_uri_1.default.parse(url);
    if (uri.scheme === 'file') {
      return new Promise((resolve, reject) => {
        fs.readFile(uri.fsPath, 'UTF-8', (err, result) => {
          err ? reject('') : resolve(result.toString());
        });
      });
    }
    try {
      const response = await request_light_1.xhr({ url, followRedirects: 5 });
      return response.responseText;
    } catch (error) {
      return Promise.reject(
        error.responseText || request_light_1.getErrorStatusDescription(error.status) || error.toString()
      );
    }
  }
  // protected resolveCompletion(item: CompletionItem): Thenable {
github microsoft / BotFramework-Composer / Composer / packages / tools / language-servers / language-generation / src / LGServer.ts View on Github external
protected async resolveSchema(url: string): Promise {
    const uri = URI.parse(url);
    if (uri.scheme === 'file') {
      return new Promise((resolve, reject) => {
        // eslint-disable-next-line security/detect-non-literal-fs-filename
        readFile(uri.fsPath, 'UTF-8', (err, result) => {
          err ? reject('') : resolve(result.toString());
        });
      });
    }
    try {
      const response = await xhr({ url, followRedirects: 5 });
      return response.responseText;
    } catch (error) {
      return Promise.reject(error.responseText || getErrorStatusDescription(error.status) || error.toString());
    }
  }
github threadheap / serverless-ide-vscode / packages / language-server / src / language-service / services / request / index.ts View on Github external
export default async (
	uri: string,
	options: XHROptions = {}
): Promise => {
	try {
		const response = await xhr(
			Object.assign(
				{
					url: uri,
					followRedirects: 5,
					headers: { "Accept-Encoding": "gzip, deflate" }
				},
				options
			)
		)
		return response.responseText
	} catch (error) {
		sendException(error)
		return (
			error.responseText ||
			getErrorStatusDescription(error.status) ||
			error.toString()
github celador / ForceCode / src / dx / sObjectDescribe.ts View on Github external
const batchRequestUrl = batchUrlElements.join('/');
    const options: XHROptions = {
      type: 'POST',
      url: batchRequestUrl,
      headers: {
        'Content-Type': 'application/json',
        Accept: 'application/json',
        Authorization: `OAuth ${orgInfo.accessToken}`,
        'User-Agent': 'salesforcedx-extension',
        'Sforce-Call-Options': `client=${CLIENT_ID}`,
      },
      data: JSON.stringify(batchRequest),
    };

    try {
      const response: XHRResponse = await xhr(options);
      const batchResponse = JSON.parse(response.responseText) as BatchResponse;
      const fetchedObjects: SObject[] = [];
      let i = nextToProcess;
      for (const sr of batchResponse.results) {
        if (sr.result instanceof Array) {
          if (sr.result[0].errorCode && sr.result[0].message) {
            notifications.writeLog(`Error: ${sr.result[0].message} - ${types[i]}`);
          }
        }
        i++;
        fetchedObjects.push(sr.result);
      }
      return Promise.resolve(fetchedObjects);
    } catch (error) {
      const xhrResponse: XHRResponse = error;
      return Promise.reject(xhrResponse.responseText);

request-light

Lightweight request library. Promise based, with proxy support.

MIT
Latest version published 4 months ago

Package Health Score

75 / 100
Full package analysis