Created
September 15, 2016 20:22
-
-
Save crobinson42/217f619e5d5f9133b700ecc04533eb12 to your computer and use it in GitHub Desktop.
js-data-express schema validation
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 express = require('express') | |
| const app = express() | |
| const jsData = require('js-data') | |
| const jsDataExpress = require('js-data-express') | |
| const store = new jsData.Container() | |
| const MongoDBAdapter = require('js-data-mongodb') | |
| const adapter = new MongoDBAdapter.MongoDBAdapter({debug: false, uri:'mongodb://localhost:27017/my-dev-db'}) | |
| store.registerAdapter('mongodb', adapter, { default: true }) | |
| const userMapper = store.defineMapper('user', { | |
| schema: { | |
| type: 'object', | |
| properties: { | |
| id: { type: 'number' }, | |
| name: { type: 'string' } | |
| } | |
| } | |
| }) | |
| app.use('/user', new jsDataExpress.Router(userMapper).router) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment