Permalink
Browse files

Add a more complex example: fetch

  • Loading branch information...
rricard committed Nov 29, 2015
1 parent 4d773e0 commit f6182e6ddc55231a7679e4acd712a9d3651c4462
Showing with 48 additions and 0 deletions.
  1. +27 −0 lambdas/fetch.js
  2. +3 −0 package.json
  3. +18 −0 tests/fetch.js
@@ -0,0 +1,27 @@
/* @flow */
import fetch from "node-fetch";
import type {LambdaContext} from "../lib/lambda-types.js";
type FetchOptions = {
url: string,
method?: string,
headers?: {[key: string]: string},
body?: string
};
export function handler({
url,
method,
headers,
body
}: FetchOptions, context: LambdaContext): void {
fetch(url, {
method: method || "GET",
headers: headers || {},
body: body
})
.then(res => res.text())
.then(context.succeed, context.fail);
}
@@ -34,5 +34,8 @@
"json-loader": "^0.5.3",
"mocha": "^2.3.4",
"webpack": "^1.12.8"
},
"dependencies": {
"node-fetch": "^1.3.3"
}
}
@@ -0,0 +1,18 @@
/* @flow */
import assert from "assert";
import {lambdaPromisifier} from "../lib/lambda-promisifier.js"
import {handler} from "../lambdas/fetch.js"
const promisifiedFetch = lambdaPromisifier(handler);
describe("fetch lambda", function() {
it("should be able to make an http call", function(done) {
promisifiedFetch({url: "http://www.rricard.me"})
.then(res => {
assert(/Posts/.test(res));
})
.then(() => done(), done);
});
});

0 comments on commit f6182e6

Please sign in to comment.