Last active
September 19, 2017 17:17
-
-
Save vincentdesmares/2a76573cff21c0fcbc7ec7e70646903a to your computer and use it in GitHub Desktop.
Sequelize example
This file contains 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 Sequelize = require('sequelize'), | |
epilogue = require('epilogue'), | |
express = require('express'), | |
bodyParser = require('body-parser'); | |
// Define your models with Sequelize | |
// This is equivalent to defining Doctrine entities | |
let database = new Sequelize('database', 'root', 'password'); | |
let User = database.define('User', { | |
username: Sequelize.STRING | |
}); | |
// Create an Express server | |
let app = express(); | |
app.use(bodyParser.json()); | |
app.use(bodyParser.urlencoded({ extended: false })); | |
// Plug Epilogue into Express | |
epilogue.initialize({ | |
app: app, | |
sequelize: database | |
}); | |
// Configure a REST resource endpoint with Epilogue | |
let userResource = epilogue.resource({ | |
model: User, | |
endpoints: ['/users', '/users/:id'] | |
}); | |
// And that's it, GET/POST and DELETE will be available for your user entity. | |
app.listen(() => { | |
console.log('Server started!'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment