Skip to content

Instantly share code, notes, and snippets.

View deadlysyn's full-sized avatar
☁️
yelling at clouds

Mike Hoskins deadlysyn

☁️
yelling at clouds
View GitHub Profile
"engines": {
"node": "8.9.4",
"npm": "5.6.0"
}
---
applications:
- name: chowchow
memory: 512M
instances: 1
random-route: true
// Community example of multiple requests with Axios...
function A() {
return axios.get(API + '/A');
}
function B() {
return axios.get(API + '/B');
}
// Axios
const btnAxios = document.querySelector('#btnAxios')
btnAxios.addEventListener('click', function() {
axios.get(API)
.then(function(res) {
PRICE.textContent = res.data.bpi.USD.rate + ' USD'
})
.catch(function(err) {
// jQuery
$('#btnJquery').click(function() {
$.getJSON(API)
.done(function(data) {
$('#price').text(data.bpi.USD.rate + ' USD')
})
.fail(function(err) {
console.log(err)
})
// Fetch
const btnFetch = document.querySelector('#btnFetch')
btnFetch.addEventListener('click', function() {
fetch(API)
.then(function(res) {
res.json()
.then(function(data) {
PRICE.textContent = data.bpi.USD.rate + ' USD'
// XHR
const btnXHR = document.querySelector('#btnXHR')
btnXHR.addEventListener('click', function() {
let XHR = new XMLHttpRequest()
XHR.onreadystatechange = function() {
if (XHR.readyState == 4 && XHR.status == 200) {
PRICE.textContent = JSON.parse(XHR.responseText).bpi.USD.rate + ' USD'
}
<html>
<head>
<link rel="stylesheet" href="style.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
</head>
<body>
<h1>Bitcoin Price Checker</h1>
<ul>
<li id="btnXHR">XHR</li>
const API = 'https://api.coindesk.com/v1/bpi/currentprice.json'
const PRICE = document.querySelector('#price')
function searchYelp(queryString, callback) {
let options = {
headers: {'Authorization': 'Bearer ' + APIKEY},
hostname: APIHOST,
path: APIPREFIX + queryString,
port: 443
}
https.get(options, function(res) {
res.setEncoding("utf8")
let body = ""