Skip to content

Instantly share code, notes, and snippets.

@championswimmer
Created April 3, 2019 08:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save championswimmer/2e3a309b880fdd2a9b12c1c3e0214bda to your computer and use it in GitHub Desktop.
Save championswimmer/2e3a309b880fdd2a9b12c1c3e0214bda to your computer and use it in GitHub Desktop.
todolist
const express = require('express')
const app = express()
let todos = []
app.use(express.json())
app.use(express.urlencoded({extended: true}))
app.get('/todos', (req, res) => {
res.send(todos)
})
app.get('/todos/:id', (req, res) => {
res.send(todos[req.params.id])
})
app.post('/todos', (req, res) => {
todos.push({
task: req.body.task,
priority: parseInt(req.body.priority)
})
res.send({success: true, message: todos.length})
})
app.listen(7070)
/**
* /todos -
* GET fetch all todos
* POST add a new todo
*
* /todos/:id -
* GET - fetch single todo
* PUT - replace a todo
* PATCH - update data of a todo
* DELETE - delete the todo
*
* Appropriate error messages for operations not possible
* Also send todos array length in response
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment