This repository is a API REST with Nodejs, Express and MySQL.
Using Nodejs v10.3, Express, MySQL preferably.
Using MySQL preferably.
Using Postman or RestEasy to feed the api.
$ git clone https://github.com/DanielArturoAlejoAlvarez/Morfeo.git [NAME APP]
$ npm install
$ npm run dev
Follow the following steps and you're good to go! Important:
...
router.get('/api/users', UserCtrl.index)
router.get('/api/users/:id',UserCtrl.show)
router.post('/api/users', UserCtrl.create)
router.put('/api/users/:id', UserCtrl.edit)
router.delete('/api/users/:id', UserCtrl.destroy)
...
...
function create(req,res){
const userData = {
iduser: null,
username: req.body.username,
email: req.body.email,
password: req.body.password,
created_at: null,
updated_at: null
}
User.saveUser(userData, (err,data)=>{
if(data && data.insertId){
res.status(200).json({
success: true,
msg: 'User saved!',
data: data
})
}else{
res.status(500).json({
success: false,
msg: 'ERROR'
})
}
})
}
...
...
userModel.saveUser = (userData,callback)=>{
if(DB){
DB.query("INSERT INTO users SET ?", userData, (err,row)=>{
if(err){
throw err
}else{
callback(null, {
insertId: row.insertId
})
}
})
}
}
...
Bug reports and pull requests are welcome on GitHub at https://github.com/DanielArturoAlejoAlvarez/Morfeo. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.
The gem is available as open source under the terms of the MIT License.