Last active
November 4, 2019 22:38
-
-
Save jasheloper/8dde9a73f5f2d78248fcff63a960f94a to your computer and use it in GitHub Desktop.
Sample CRUD server; CREATE, READ, UPDATE, DESTORY
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 express = require('express'); | |
const port = 5000; | |
const server = express(); | |
server.use(express.json()) | |
server.get('/hobbits', (req, res) => { | |
res.send('Welcome to Hobbiton!'); | |
}); // READ data | |
server.post('/hobbits', (req, res) => { | |
res.status(201).json({url: '/hobbits', operation: 'POST'}); | |
}) // CREATE data | |
server.put('/hobbits', (req, res) => { | |
res.status(200).json({url: '/hobbits', operation: 'PUT'}); | |
}) // UPDATE data | |
server.delete('/hobbits', (req, res) => { | |
res.status(204); | |
}); // DESTORYING data | |
server.listen(port, () => { | |
console.log(`server listening on port ${port}`) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment