Skip to content

Instantly share code, notes, and snippets.

@killshot13
Created February 7, 2022 09:04
Show Gist options
  • Save killshot13/39b15fea833e843ee34571464653af8d to your computer and use it in GitHub Desktop.
Save killshot13/39b15fea833e843ee34571464653af8d to your computer and use it in GitHub Desktop.
Sample express.route config with nested GET, POST, PUT, & DELETE routes.
app
.route('/api')
.get((req, res) => {
res.setHeader('Cache-Control', 'no-cache,no-store,max-age=0,must-revalidate')
res.setHeader('Pragma', 'no-cache')
res.setHeader('Expires', '-1')
res.send('The data was retrieved successfully!')
})
.post((req, res) => {
res.setHeader('Cache-Control', 'no-cache,no-store,max-age=0,must-revalidate')
res.setHeader('Pragma', 'no-cache')
res.setHeader('Expires', '-1')
res.send('The data was saved successfully!')
})
.put((req, res) => {
res.setHeader('Cache-Control', 'no-cache,no-store,max-age=0,must-revalidate')
res.setHeader('Pragma', 'no-cache')
res.setHeader('Expires', '-1')
res.send('The data was updated successfully!')
})
.delete((req, res) => {
res.setHeader('Cache-Control', 'no-cache,no-store,max-age=0,must-revalidate')
res.setHeader('Pragma', 'no-cache')
res.setHeader('Expires', '-1')
res.send('The data was deleted successfully!')
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment