Below is a collection of different HTTP clients in the following language:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Make native http/https requests | |
* | |
* @usage: NativeRequest([URL|options]) | |
* @demo: NativeRequest('https://example.org') | |
* | |
* @output: <http.ClientRequest> - see https://nodejs.org/api/http.html#http_http_request_options_callback | |
*/ | |
const { URL } = require('url') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Simple RegExp capture | |
*/ | |
function regexp_capture(regexp, data) | |
{ | |
if (!data) | |
{ return false; } | |
var output = (new RegExp(regexp)).exec(data); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
application/EDI-X12 | |
application/EDIFACT | |
application/epub+zip | |
application/java-archive | |
application/javascript | |
application/json | |
application/ld+json | |
application/ms-word | |
application/msword | |
application/octet-stream |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict"; | |
class EventListener { | |
constructor () { | |
// Declare variables | |
this._onEvents = []; | |
return this; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Quick express-app to retrieve OAuth credentials | |
* | |
* Run it with $ node index.js | |
*/ | |
const express = require('express') | |
const request = require('request') | |
const app = express() |
Let's see how to post a message with a Slack bot, using Bearer.sh.
- Create a custom API on Bearer.sh dashboard (learn how here).
- Use the configuration below for that custom API
- Create a Slack bot on Slack (link)
- Register the Bot API Key on Bearer (it starts with
xoxb-...
) - Post to a channel using the snippet below
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Bearer = require('@bearer/node-agent') | |
Bearer.init({ secretKey: '...' }) | |
import * as functions from 'firebase-functions' | |
import axios from 'axios' | |
export const test = functions.https.onRequest((request, response) => { | |
response.send('Hello from Firebase!') | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Require the library and client | |
const circuitBreaker = require("opossum") | |
const apiClient = require("our-example-api-client") | |
// Our example request | |
const getPosts = (req, res, next) => { | |
// Wrap our client get method in the circuit breaker | |
const breaker = circuitBreaker(apiClient.get, { | |
timeout: 3000, | |
errorThresholdPercentage: 50, | |
resetTimeout: 5000 |
OlderNewer