Skip to content

Instantly share code, notes, and snippets.

const express = require('express')
const bodyParser = require('body-parser')
const app = express()
const port = process.env.PORT || 3010
app.use(bodyParser.json())
app.get('/data', (req, res) => {
const data = [
{
const get = require('lodash.get')
const set = require('lodash.set')
const cloneDeep = require('lodash.clonedeep')
const got = require('got')
module.exports = {
makeRequest
}
async function makeRequest (payload) {
function composeRequest (payload) {
const newPayload = cloneDeep(payload)
const { host, headers, method, endpoint } = get(payload, 'data.config', {})
const requestOptions = {
uri: new URL(endpoint, host),
options: {
headers,
method
}
}
test('composeRequest() should compose request options so they can be consumed by the GOT http customer module ', async function ({ deepEqual, end }) {
const config = {
endpoint: 'foo',
host: 'http://localhost:3333',
method: 'GET',
headers: { 'content-type': 'application/json' }
}
// composeRequest :: Payload -> Payload
const actual = composeRequest(deepFreeze(lift(config)))
const expected = {
function composeRequest (payload) {
const config = payload.data.config
const endpoint = config.endpoint
const base = config.host
const headers = config.headers
const method = config.method
const requestOptions = {
uri: new URL(endpoint, base),
options: {
headers,
// ...
test('composeRequest() should compose request options so they can be consumed by the GOT http customer module ', async function ({ deepEqual, end }) {
const config = {
endpoint: 'foo',
host: 'http://localhost:3333',
method: 'GET',
headers: { 'content-type': 'application/json' }
}
// composeRequest :: Payload -> Payload
app.get('/stores', (req, res) => {
const responseBody = pipe(
composeRequest,
makeRequest,
composeResponse
)(lift(config))
// ...
})
pipe(
// ...
)(lift(req.body))
function lift(config = {}, body = {}) {
return {event: {body}, data: {config}, result: {}}
}
pipe(
// ...
)({
event: {
body: req.body
},
data: { config },
result: {}
})
const express = require('express')
const bodyParser = require('body-parser')
const {pipe} = require('./tools')
const app = express()
const port = process.env.PORT || 3000
app.use(bodyParser.json())
app.get('/stores', (req, res) => {
const responseBody = pipe(