Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'http-call' in functional components in JavaScript. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.
let app = require('../lib/server')
let request = require('supertest').agent(app.listen())
let user = require('../lib/user')
let redis = require('../lib/redis')
let co = require('co')
let url = require('url')
let crypto = require('crypto')
let fs = require('fs')
let config = require('../lib/config')
let expect = require('unexpected')
let sinon = require('sinon')
let http = require('http-call').HTTP
let storageBackends = require('./_storage_backends')
// make sure this user is in the htpasswd file
const testUser = {name: 'test', password: 'test'}
function * deleteItems (prefix) {
let items = yield config.storage.list(prefix)
for (let item of items) {
console.log(`deleting ${item}`)
yield config.storage.delete(item)
}
}
function bearer (token) {
return function (request) {
request.set('Authorization', `Bearer ${token}`)
}
if (downstreamApp.hash === targetApp.hash) {
return cli.log(`\n${color.app(targetApp.name)} is up to date with ${color.app(downstreamApp.name)}`)
}
// Do the actual Github diff
try {
const path = `${targetApp.repo}/compare/${downstreamApp.hash}...${targetApp.hash}`
const headers: { authorization: string; 'user-agent'?: string} = {authorization: 'token ' + githubToken}
if (herokuUserAgent) {
headers['user-agent'] = herokuUserAgent
}
const githubDiff: any = await HTTP.get(`https://api.github.com/repos/${path}`, {
headers,
}).then(res => res.body)
cli.log('')
cli.styledHeader(`${color.app(targetApp.name)} is ahead of ${color.app(downstreamApp.name)} by ${githubDiff.ahead_by} commit${githubDiff.ahead_by === 1 ? '' : 's'}`)
const mapped = githubDiff.commits.map((commit: any) => {
return {
sha: commit.sha.substring(0, 7),
date: commit.commit.author.date,
author: commit.commit.author.name,
message: commit.commit.message.split('\n')[0],
}
}).reverse()
cli.table(mapped, {
sha: {
header: 'SHA',
const getWeather = cache('weather', async ({ latitude, longitude }: LatLon) => {
// notify('fetching weather data')
debug('fetching weather...')
const { body } = await HTTP.get(`https://api.forecast.io/forecast/${forecastIOApiKey}/${latitude},${longitude}`)
return body as IWeatherResponse
})
async function run () {
const { body } = await HTTP.post(`https://api.github.com/app/installations/${installation}/access_tokens`, {
headers: {
Authorization: `Bearer ${token}`,
Accept: 'application/vnd.github.machine-man-preview+json"'
}
})
console.log(body.token)
}
async function readLogsV1 (logplexURL) {
let {response} = await HTTP.stream(logplexURL)
return new Promise(function (resolve, reject) {
response.setEncoding('utf8')
liner.setEncoding('utf8')
response.pipe(liner)
liner.on('data', line => cli.log(colorize(line)))
response.on('end', resolve)
response.on('error', reject)
})
}
async function readLogsV1 (logplexURL) {
let {response} = await HTTP.stream(logplexURL)
return new Promise(function (resolve, reject) {
response.setEncoding('utf8')
liner.setEncoding('utf8')
response.pipe(liner)
liner.on('data', line => cli.log(colorize(line)))
response.on('end', resolve)
response.on('error', reject)
})
}
async function readLogsV1(logplexURL: string) {
const {response} = await HTTP.stream(logplexURL)
return new Promise(function (resolve, reject) {
response.setEncoding('utf8')
liner.setEncoding('utf8')
response.pipe(liner)
liner.on('data', line => cli.log(colorize(line)))
response.on('end', resolve)
response.on('error', reject)
})
}
request(url: any, options: any = {}) {
options.headers = {
Authorization: `Token ${this.token}`,
'User-Agent': this.version,
...options.headers,
}
return HTTP.get(`${GITHUB_API}${url}`, options)
}
const {flags} = this.parse(Status)
const apiPath = '/api/v4/current-status'
const capitalize = (str: string) => str.substr(0, 1).toUpperCase() + str.substr(1)
const printStatus = (status: string) => {
const colorize = (color as any)[status]
let message = capitalize(status)
if (status === 'green') {
message = 'No known issues at this time.'
}
return colorize(message)
}
let host = process.env.HEROKU_STATUS_HOST || 'https://status.heroku.com'
let {body} = await HTTP.get(host + apiPath)
if (flags.json) {
cli.styledJSON(body)
return
}
for (let item of body.status) {
let message = printStatus(item.status)
this.log(`${(item.system + ':').padEnd(11)}${message}`)
}
for (let incident of body.incidents) {
cli.log()
cli.styledHeader(`${incident.title} ${color.yellow(incident.created_at)} ${color.cyan(incident.full_url)}`)
request(url: string, options: any = {}) {
options.headers = {
Authorization: `Bearer ${this.token}`,
'User-Agent': this.version
}
if (['POST', 'PATCH', 'DELETE'].includes(options.method)) {
options.headers['Content-type'] = 'application/json'
}
return HTTP.request(KOLKRABBI_BASE_URL + url, options).then((res: any) => res.body)
}