Giter Site home page Giter Site logo

falcor-lambda's Introduction

falcor-lambda Build Status npm version

Greenkeeper badge

It creates AWS Lambda handler from Falcor's data source.

You can setup a Falcor endpoint on AWS API Gateway and Lambda using serverless-falcor-starter. This project exposes the Falcor endponit using falcor-lambda.

Usage

You can create a Lambda handler function. For example:

/* handler.js */

import dataSourceHanlder from "falcor-lambda";
import Router from "falcor-router";

module.exports.handler = dataSourceHanlder(() => new Router([{
  route: "greeting",
  get: function() {
    return { path: ["greeting"], value: "Hello, world" };
  }
}]));

API

function dataSourceHanlder(sourceCreateFn: SourceCreateFn, option?: Option): LambdaHandlerFunction

Creates a Lambda handler.

  • sourceCreateFn: A function which returns a Falcor DataSource.

type SourceCreateFn: (event?: any, context?: any) => DataSource

  • event: An event argument of the AWS Lambda function.
  • context: A context argument of the AWS Lambda function.

type Option: {debug?: boolean, eventToFalcorContext?: (event: any, context: any) => FalcorContext}

  • debug: Allows to output debug log.
  • eventToFalcorContext: This function creates a FalcorContext object from the Lambda's event or context value. See also Request and event mapping

type FalcorContext: {method: string, jsonGraph?: JSONGraphEnvelope, callPath?: Path, arguments?: any[], pathSuffixes?: Pathset[], paths?: PathSet[]}

FalcorContext represents Falcor DataSource's get/set/call arguments.

Request and event mapping

If you integrate a Lambda handler with AWS API Gateway, you must create a mapping from request to Lambda events with API Request Mapping. falcor-lambda assumes that the request parameter of the GET/POST method will be mapped in the following way:

  • GET
"requestTemplates": {
  "application/json": {
    "method": "$input.params().querystring.method",
    "paths": "$util.escapeJavaScript($input.params().querystring.paths)"
  }
}
  • POST
"requestTemplates": {
  "application/json": {
    "method": "$input.json('$.method')",
    "jsonGraph": "$input.json('$.jsonGraph')",
    "callPath": "$input.json('$.callPath')",
    "arguments": "$input.json('$.arguments')",
    "pathSuffixes": "$input.json('$.pathSuffixes')",
    "paths": "$input.json('$.paths')"
  }
}

If you want the complete example, please see falcor-lambda-example/falcor/model/s-function.json

By the default, falcor-lambda parses the each value of the event object using JSON.parse because assumption that they are stringified JSON parameter. If you use other mapping, witch is different from the above sample, you can pass through request values to your DataSource with customizing eventToFalcorContext.

License

This software is released under the MIT License, see LICENSE.txt.

falcor-lambda's People

Contributors

greenkeeper[bot] avatar quramy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

sirceljm

falcor-lambda's Issues

NPM package broken

Hi,

The NPM package is broken, and I believe your build script is also broken.

When installed, the NPM package is pretty much empty (just the readme,license, and package.json).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.