https://github.com/ratson/koa-falcor
Koa Middleware for Hosting Falcor Data Sources.
https://github.com/ratson/koa-falcor
Last synced: about 1 year ago
JSON representation
Koa Middleware for Hosting Falcor Data Sources.
- Host: GitHub
- URL: https://github.com/ratson/koa-falcor
- Owner: ratson
- Created: 2016-04-17T10:58:21.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2018-02-11T00:51:47.000Z (over 8 years ago)
- Last Synced: 2024-10-18T21:58:49.072Z (over 1 year ago)
- Language: JavaScript
- Size: 22.5 KB
- Stars: 5
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# koa-falcor
[Koa](https://github.com/koajs/koa) Middleware for Hosting [Falcor](https://github.com/Netflix/falcor) Data Sources.
`dataSourceRoute` is port from [falcor-express](https://github.com/Netflix/falcor-express).
## Installation
```sh
npm install koa-falcor koa koa-route --save
```
## Usage
```js
const falcor = require('koa-falcor')
const Koa = require('koa')
const route = require('koa-route')
const app = new Koa()
app.use(route.get('/model.json', falcor([{
route: 'greeting',
get() {
return {
path: ['greeting'],
value: 'Hello World!',
}
},
}])))
app.listen(3000)
```
Then access the JSON Graph via `http://localhost:3000/model.json?paths=[["greeting"]]&method=get`
## Create Router Manually
```sh
npm install koa-falcor koa koa-bodyparser koa-route falcor-router --save
```
```js
const { dataSourceRoute } = require('koa-falcor')
const bodyParser = require('koa-bodyparser')
const Koa = require('koa')
const route = require('koa-route')
const Router = require('falcor-router')
const app = new Koa()
app.use(bodyParser())
app.use(route.get('/model.json', dataSourceRoute(() => new Router([{
route: 'greeting',
get() {
return {
path: ['greeting'],
value: 'Hello World!',
}
},
}]))))
app.listen(3000)
```