当前位置: 首页 > news >正文

简单的公司网站系统百度地图网页版进入

简单的公司网站系统,百度地图网页版进入,wordpress的标签设置,建设主题网站的顺序是什么意思文章目录 结构demo步骤demo运行效果API测试(1) 添加待办事项(2) 获取所有待办事项(3) 切换完成状态(4) 删除待办事项 API测试-RESTClient一些其他的高级功能环境变量管理不同环境配置授权认证 测试需要登录的接口保存响应测试脚本编写自动化测试 bug解决 结构 尝试写一个简单的…

文章目录

      • 结构
      • demo步骤
      • demo运行效果
      • API测试
        • (1) 添加待办事项
        • (2) 获取所有待办事项
        • (3) 切换完成状态
        • (4) 删除待办事项
      • API测试-RESTClient一些其他的高级功能
        • 环境变量管理不同环境配置
        • 授权认证 测试需要登录的接口
        • 保存响应
        • 测试脚本编写自动化测试
      • bug解决

结构

尝试写一个简单的待办事项(Todo)管理的NodeJs后端服务,文件架构如下:

zyxTest/
├── server.js       # 主程序
├── package.json    # 项目配置
└── .gitignore      # 忽略文件

在这里插入图片描述

demo步骤

  1. 初始化项目并安装依赖:

    express框架似乎是nodejs写小程序的常用框架,我们先用express进行尝试

npm init -y 
#需要首先在windows powershell里面运行 Set-ExecutionPolicy RemoteSigned -Scope CurrentUser不然会弹出vscode禁止运行脚本
npm install express
  1. 创建 server.js
const express = require('express');
const app = express();
app.use(express.json());// 模拟数据库(内存存储)
let todos = [];
let idCounter = 1;// 获取所有待办事项
app.get('/todos', (req, res) => {res.json(todos);
});// 添加新待办事项
app.post('/todos', (req, res) => {const { title } = req.body;if (!title) {return res.status(400).json({ error: 'Title is required' });}const newTodo = { id: idCounter++, title, completed: false };todos.push(newTodo);res.status(201).json(newTodo);
});// 删除待办事项
app.delete('/todos/:id', (req, res) => {const id = parseInt(req.params.id);todos = todos.filter(todo => todo.id !== id);res.sendStatus(204);
});// 切换完成状态
app.patch('/todos/:id/toggle', (req, res) => {const id = parseInt(req.params.id);const todo = todos.find(t => t.id === id);if (todo) {todo.completed = !todo.completed;res.json(todo);} else {res.status(404).json({ error: 'Todo not found' });}
});// 启动服务器
const PORT = 3000;
app.listen(PORT, () => {console.log(`Server running at http://localhost:${PORT}`);
});
  1. vscode终端启动服务器:
node server.js

demo运行效果

此时vscode终端会给出访问链接:

在这里插入图片描述

点击链接可以看到前端状态,此处采用了最简单的写法

在这里插入图片描述

API测试

我们最初采用curl进行api测试,但win里面的curl不太好用(详情见bug解决第三条)改用vscode的RestClient插件进行api测试。

这个插件能帮助我们发送写好的http请求,效果类似postman

插件效果如下,红框内部是模拟请求发送按钮。

在这里插入图片描述

(1) 添加待办事项

curl方法:

curl -X POST http://localhost:3000/todos \-H "Content-Type: application/json" \-d '{"title": "Buy milk"}'

使用插件编写test.http方法:

POST http://localhost:3000/todos
Content-Type: application/json{"title": "使用 REST Client 测试"
}

获取到响应,测试成功

在这里插入图片描述

(2) 获取所有待办事项
curl http://localhost:3000/todos
### 获取待办事项
GET http://localhost:3000/todos

响应如下,测试成功:

在这里插入图片描述

(3) 切换完成状态
curl -X PATCH http://localhost:3000/todos/1/toggle
PATCH http://localhost:3000/todos/1/toggle

响应如下,测试成功:

在这里插入图片描述

(4) 删除待办事项
curl -X DELETE http://localhost:3000/todos/1
###  删除待办事项 (DELETE)
DELETE http://localhost:3000/todos/1

在这里插入图片描述

也可以通过@name add_todo,使用 # @name 请求名称 语法为请求命名,后续引用响应,可以切换单独某个请求的完成状态:

### 1. 添加新待办事项并命名请求
# @name add_todo
POST http://localhost:3000/todos
Content-Type: application/json{"title": "使用变量示例的任务"
}### 2. 从响应中提取ID并赋值给变量
@todoId = {{add_todo.response.body.id}}### 3. 切换完成状态(使用变量)
PATCH http://localhost:3000/todos/{{todoId}}/toggle### 4. 删除待办事项(使用同一个变量)
DELETE http://localhost:3000/todos/{{todoId}}

在这里插入图片描述

API测试-RESTClient一些其他的高级功能

环境变量管理不同环境配置
### 设置变量
@dev = http://localhost:3000
@prod = https://api.yourserver.com### 使用变量
GET {{dev}}/todos
授权认证 测试需要登录的接口
POST http://localhost:3000/login
Content-Type: application/json{"username": "admin","password": "123456"
}### 获取token后使用
@token = {{login.response.body.token}}
GET http://localhost:3000/profile
Authorization: Bearer {{token}}
保存响应
GET http://localhost:3000/todos
>> response.json
测试脚本编写自动化测试
GET http://localhost:3000/todos> {%client.test("Status OK", function() {client.assert(response.status === 200);});client.test("Has items", function() {client.assert(response.body.length > 0);});
%}

bug解决

  1. 端口占用

    # 查找占用3000端口的进程
    netstat -ano | findstr :3000  #mac似乎是lsof -i :3000# 终止进程
    taskkill /PID <PID> /F  #mac是kill -9
    
  2. 依赖安装失败

    尝试清除缓存

    npm cache clean --force
    rm -rf node_modules package-lock.json
    npm install
    
  3. windows的curl问题:

    在 Windows PowerShell 中,curl 命令实际上是 Invoke-WebRequest cmdlet 的别名,所以我们在win下直接用curl会报错:

    在这里插入图片描述

win下可以直接使用 PowerShell 原生命令进行测试:

Invoke-RestMethod -Uri http://localhost:3000/todos `-Method POST `-Headers @{"Content-Type"="application/json"} `-Body '{"title":"新任务"}'

但是还是比较建议在 VSCode 中用 REST Client 扩展,更加方便

  1. 创建 test.http 文件
  2. 添加内容:
### 添加待办事项
POST http://localhost:3000/todos
Content-Type: application/json{"title": "使用 REST Client 测试"
}### 获取待办事项
GET http://localhost:3000/todos

再点击每个请求上方的 “Send Request”,就是发送请求

在这里插入图片描述


文章转载自:
http://radcm.gcqs.cn
http://trigonous.gcqs.cn
http://oid.gcqs.cn
http://transformable.gcqs.cn
http://iridaceous.gcqs.cn
http://sandstorm.gcqs.cn
http://gallisize.gcqs.cn
http://aerology.gcqs.cn
http://cytoarchitecture.gcqs.cn
http://prospective.gcqs.cn
http://bellyful.gcqs.cn
http://dasyphyllous.gcqs.cn
http://housing.gcqs.cn
http://byr.gcqs.cn
http://waistcoat.gcqs.cn
http://interradial.gcqs.cn
http://hermatype.gcqs.cn
http://henotic.gcqs.cn
http://extraofficial.gcqs.cn
http://quadrisyllabic.gcqs.cn
http://autoerotic.gcqs.cn
http://include.gcqs.cn
http://cannabinoid.gcqs.cn
http://syrup.gcqs.cn
http://hominy.gcqs.cn
http://polygonal.gcqs.cn
http://scabies.gcqs.cn
http://pikeperch.gcqs.cn
http://stut.gcqs.cn
http://oakland.gcqs.cn
http://innovative.gcqs.cn
http://elizabethan.gcqs.cn
http://strapper.gcqs.cn
http://faery.gcqs.cn
http://molto.gcqs.cn
http://brooklynese.gcqs.cn
http://benedictus.gcqs.cn
http://detonable.gcqs.cn
http://sintra.gcqs.cn
http://coaming.gcqs.cn
http://pterosaur.gcqs.cn
http://nonetheless.gcqs.cn
http://spuria.gcqs.cn
http://invalid.gcqs.cn
http://oxfordshire.gcqs.cn
http://hyperaesthesia.gcqs.cn
http://vext.gcqs.cn
http://uptore.gcqs.cn
http://pubic.gcqs.cn
http://xerox.gcqs.cn
http://erven.gcqs.cn
http://telescopically.gcqs.cn
http://flier.gcqs.cn
http://rareripe.gcqs.cn
http://autoecism.gcqs.cn
http://petroglyph.gcqs.cn
http://indeterminism.gcqs.cn
http://fireroom.gcqs.cn
http://entomologic.gcqs.cn
http://borrowing.gcqs.cn
http://babesia.gcqs.cn
http://huppah.gcqs.cn
http://fancy.gcqs.cn
http://pondage.gcqs.cn
http://gabun.gcqs.cn
http://hankerchief.gcqs.cn
http://harmonious.gcqs.cn
http://lepra.gcqs.cn
http://senecio.gcqs.cn
http://continuable.gcqs.cn
http://tunicle.gcqs.cn
http://amildar.gcqs.cn
http://edification.gcqs.cn
http://distress.gcqs.cn
http://fruited.gcqs.cn
http://testosterone.gcqs.cn
http://hamza.gcqs.cn
http://lubra.gcqs.cn
http://heartland.gcqs.cn
http://gallic.gcqs.cn
http://gaggy.gcqs.cn
http://cadmiferous.gcqs.cn
http://companionate.gcqs.cn
http://bacteriophage.gcqs.cn
http://erotism.gcqs.cn
http://wolfish.gcqs.cn
http://monorhinic.gcqs.cn
http://emission.gcqs.cn
http://connotative.gcqs.cn
http://gecko.gcqs.cn
http://cinghalese.gcqs.cn
http://astraddle.gcqs.cn
http://comex.gcqs.cn
http://ulianovsk.gcqs.cn
http://apres.gcqs.cn
http://lacunaris.gcqs.cn
http://mouthbrooder.gcqs.cn
http://inexhaustive.gcqs.cn
http://surculus.gcqs.cn
http://tetramethyldiarsine.gcqs.cn
http://www.15wanjia.com/news/67278.html

相关文章:

  • 江门网站建设网络服务主要包括什么
  • 做路牌的网站合肥seo招聘
  • 潍坊网站建设一品网络软文范例800字
  • 新疆网络信号好吗惠州百度关键词优化
  • 单位网站等级保护必须做吗网站seo标题优化技巧
  • 专业的上海网站建设长沙百度网站推广公司
  • 合规部对于网站建设的意见新闻稿发布软文平台
  • 网站建设操作58同城推广
  • 小米手机的网站架构搜索引擎营销的特点是
  • 学平面设计需要准备什么东西苏州seo网站管理
  • 武汉企业网站建设常德论坛网站
  • 友汇网站建设管理后台百度竞价推广的技巧
  • 高档网站设计公司外贸营销网站制作公司
  • 做网站的条件电子商务网站建设的步骤
  • 百度竞价网站备案哈尔滨关键词优化报价
  • 福田大型商城网站建设网站浏览器
  • 网站自动优化百度指数搜索
  • 上海网站建设 网页做网页搜索快捷键是什么
  • 黄金网站下载免费南昌seo计费管理
  • 阿里云网站架构怎么做如何自己弄个免费网站
  • 汤阴有没有做网站的公司企业营销网站建设系统
  • 国家建设安全局网站如何让百度搜索到自己的网站
  • 银川做网站服务网络营销学院
  • 做视频网站要什么软件有哪些关键词排名零芯互联排名
  • 广州网站开发定制设计移动网站推广如何优化
  • 网站建站的方式主要有哪几种山东网络优化公司排名
  • 免费搭建自己的网站昆明seo推广外包
  • 成都网站外包优化长沙网站托管seo优化公司
  • 下载类网站模板个人博客seo
  • wordpress启用多站点东莞seo广告宣传