官网文档 https://cloud.tencent.com/document/product/876/19368

  1. router.post('/', async (req, res) => {
  2. if (req.body.title == undefined) {
  3. return
  4. }
  5. const createData = {
  6. title: req.body.title,
  7. createTime: Date.now(),
  8. done: false
  9. }
  10. const backData = await db.collection('todo').add(createData)
  11. res.send(backData)
  12. })

用postman验证一下,注意是在Body中的 x-www-form-urlencoded中传入参数👇,可以看到接口成功了,并返回了插入数据的id和requestId
image.png

  1. router.put('/', async (req, res) => {
  2. if (req.body.id == undefined) {
  3. res.send('缺少id')
  4. }
  5. if (req.body.title == undefined) {
  6. return
  7. }
  8. const updateData = {
  9. title: req.body.title,
  10. }
  11. const backData = await db.collection('todo').doc(req.body.id).update(updateData)
  12. res.send(backData)
  13. })

image.png

  1. router.delete('/', async (req, res) => {
  2. if (req.body.id == undefined) {
  3. res.send('缺少id')
  4. }
  5. const backData = await db.collection('todo').doc(req.body.id).remove()
  6. res.send(backData)
  7. })

image.png