How to use the phin.promisified function in phin

To help you get started, we’ve selected a few phin 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 remoteintech / remote-jobs / bin / build-site.js View on Github external
async function request( url ) {
	console.log(
		'Requesting URL "%s"',
		url.length > 70
			? url.substring( 0, 67 ) + '...'
			: url
	);
	const res = await phin.promisified( url );
	if ( res.statusCode !== 200 ) {
		throw new Error(
			'HTTP response code ' + res.statusCode
			+ ' for URL: ' + url
		);
	}
	return res.body.toString();
}
github electerm / electerm / npm / install.js View on Github external
function getVer () {
  return rp({
    url: versionUrl,
    timeout: 15000
  })
    .then(res => res.body.toString())
}
github ethanent / Vaxic / lib / route / route.js View on Github external
res['route'] = async (opts) => {
		if (!opts) throw new Error('Missing opts property.')
		if (!opts.hasOwnProperty('origin') && !opts.hasOwnProperty('url')) throw new Error('Missing origin or url property for route options.')

		let newHeaders = req.headers

		if (newHeaders.hasOwnProperty('host')) newHeaders.host = url.parse(opts.origin).host

		try {
			let forwardRes = await p(Object.assign({
				'method': req.method,
				'headers': newHeaders,
				'url': new url.URL(req.url.pathname, opts.origin).toString()
			}, req.body ? {
				'data': req.body
			} : {}, opts, {
				'stream': true
			}))

			res.writeHead(forwardRes.statusCode, forwardRes.headers)
			forwardRes.stream.on('data', (chunk) => res.write(chunk))
			forwardRes.stream.on('end', () => res.end())
		}
		catch (err) {
			throw err
		}
github electerm / electerm / app / app.js View on Github external
async function waitUntilServerStart (url) {
  let serverStarted = false
  while (!serverStarted) {
    await rp({
      url,
      timeout: 100
    })
      .then(() => {
        serverStarted = true
      })
      .catch(() => null)
  }
}
github electerm / electerm / npm / install.js View on Github external
function getReleaseInfo (filter) {
  return rp({
    url: releaseInfoUrl,
    timeout: 15000
  })
    .then((res) => {
      return JSON.parse(res.body.toString())
        .release
        .assets
        .filter(filter)[0]
    })
}

phin

The ultra-lightweight Node.js HTTP client

MIT
Latest version published 7 months ago

Package Health Score

73 / 100
Full package analysis

Popular phin functions