四步:增删改查
作者:互联网
@url = http://localhost:3000
@json = Content-Type: application/json
### 查询 router.get("/tag",async (ctx)=>{ try{ const data =await tagModel.find({}); return success(ctx,data); } catch(error){ return fail(ctx,error); } GET {{url}}/tag
### 添加 router.post("/tag",async ctx=>{ try{ const data =await tagModel.create(ctx.request.body); return success(ctx,data); } catch(error){ return fail(ctx,error); } POST {{url}}/tag {{json}} { "text":"张三" } ### 删除 router.delete("/tag",async ctx=>{ try{ const data =await tagModel.deleteOne(ctx.request.body); return success(ctx,data); } catch(error){ return fail(ctx,error); } DELETE {{url}}/tag?_id:61a8881b29f6dd1d230327fc {{json}} ### 修改内容 router.put("/user",async ctx=>{ try{ const data =await userModel.updateOne(ctx.query,ctx.request.body); return success(ctx,data); } catch(error){ return fail(ctx,error); } PUT {{url}}/content?_id=61a8823b29f6dd1d230327c2 {{json}}
{ "top":true }
### 查询 router.get("/tag",async (ctx)=>{ try{ const data =await tagModel.find({}); return success(ctx,data); } catch(error){ return fail(ctx,error); } GET {{url}}/tag
### 添加 router.post("/tag",async ctx=>{ try{ const data =await tagModel.create(ctx.request.body); return success(ctx,data); } catch(error){ return fail(ctx,error); } POST {{url}}/tag {{json}} { "text":"张三" } ### 删除 router.delete("/tag",async ctx=>{ try{ const data =await tagModel.deleteOne(ctx.request.body); return success(ctx,data); } catch(error){ return fail(ctx,error); } DELETE {{url}}/tag?_id:61a8881b29f6dd1d230327fc {{json}} ### 修改内容 router.put("/user",async ctx=>{ try{ const data =await userModel.updateOne(ctx.query,ctx.request.body); return success(ctx,data); } catch(error){ return fail(ctx,error); } PUT {{url}}/content?_id=61a8823b29f6dd1d230327c2 {{json}}
{ "top":true }
标签:return,改查,ctx,json,tag,四步,error,增删,data 来源: https://www.cnblogs.com/zhengzhou/p/15634297.html