当前位置:网站首页>第十三届蓝桥杯(Web 应用开发)线上模拟赛【第十题】(RESTful API 开发)
第十三届蓝桥杯(Web 应用开发)线上模拟赛【第十题】(RESTful API 开发)
2022-08-08 20:32:00 【左手】
第十三届蓝桥杯(Web 应用开发)线上模拟赛参考答案全集
考试需求
请基于 users.json 补全 index.js 获取用户列表 RESTful API。 Url HTTP 方法 发送内容 响应结果 list Get 空 显示所有用户列表
解决办法
添加一个get请求的响应方法
参考代码
./index.js
var express = require('express');
var app = express();
var fs = require("fs");
var path =require('path');
app.use(express.json())
app.use(express.urlencoded({ extended: false }))
//添加用户
app.post('/add', function(req, res) {
fs.readFile(path.resolve(__dirname,'./users.json'), 'utf8', function(err, data) {
data = JSON.parse(data);
data["userlist"].push({
"id": 4,
"username": "lucy",
"password": "123456"
});
res.json(data);
});
})
//TODO:请补全获取用户列表代码
app.get('/list', function(req, res) {
fs.readFile(path.resolve(__dirname,'./users.json'), 'utf8', function(err, data) {
data = JSON.parse(data);
res.json(data.userlist);
});
})
app.listen(8080, function() {
console.log("访问地址:http://localhost:8080")
})
module.exports = app;
边栏推荐
- Kotlin annotations
- Web3到底是什么?
- 2022-08-08 第六小组 瞒春 学习笔记
- Mysql management commands
- Kotlin笔记-ForEach与ForEachIndexed区别
- 学习笔记:栈的应用1_递归(重点)
- Yarn 总结(未完待续)
- Experience Sharing | A low-cost and fast-paced approach to building an enterprise knowledge management system
- From interview to autism, five rounds of interviews for byte software testing post, four hours of soul torture...
- LeetCode_67_二进制求和
猜你喜欢

学习笔记:第二部分 队列

【无标题】

莫让“学院派”限制我们的思维:在数组的中间位置删除数据一定比链表慢?

Bluu海鲜公司推出首批实验室培育的鱼类产品

学习笔记:栈的应用1_递归(重点)

劳务派遣业务流程图

Bluu Seafood launches first lab-grown fish products

What are the role of document management system for companies?

使用fontforge修改字体,只保留数字

fillder4 keeps prompting the system proxy was changed, watch me solve it
随机推荐
暑期“小候鸟”超员增多 惠州交警提醒:安全出行不能忘
测试计划
Maykel Studio OpenHarmony Device Development Training Notes - Chapter 6 Study Notes
Mysql management commands
PHP使用glob()查找文件
源码分析MyCat专栏
Cesium中自定义材质material
五大理由告诉你为什么开发人员选择代码质量静态分析工具Klocwork来实现软件安全
Kotlin Notes - Difference Between ForEach and ForEachIndexed
JSP第二篇 -----JSP浅聊EL表达式第二篇:EL表达式中的运算符
自定义MVC
Kotlin annotations
头脑风暴:打家劫舍2
iMeta | 深圳先进院戴磊组开发可同时提取共存菌株的组成和基因成分谱的菌株分析工具...
OpenEuler's Ways to Improve Resource Utilization 02: Effects under Typical Applications
西湖大学鞠峰组招聘【塑料降解 / 污水工程 / 微生物学】方向博士后和科研助理...
LeetCode_2_两数相加
什么是仿射函数?
2022年云商店联合营销市场发展基金(MDF)介绍
实践篇1:深度学习之----LetNet之tensorflow2的实现