songc-http-utils
v1.0.0
Published
需先安装 **node** 环境,才能启动程序。
Downloads
2
Readme
原生node封装的一个简单http请求框架
运行环境
需先安装 node 环境,才能启动程序。
启动服务
## 下载依赖
npm install
## 启动服务
node app.js
端口配置
在 app.js 中设置端口
数据库配置
在 utils/connectMysql.js 中进行数据库的相关配置
请求路径与文件的关系
每一个请求都对应一个文件
如果登录接口的请求的路径是 /user/login ?name=xiaMin&pwd=123
那么对应的响应的文件就是 根目录下的 /user/login.js
所以我们的登录接口的代码就写在 /user/login.js 中。
一个文件夹下可以有多个文件,随你自己怎么存放文件,记着请求的路径就是文件路径就行
监听请求
utils/listen.js
这个文件是用来监听请求的文件,这是一个比较重要的文件。看得懂最好,看不懂也没关系。
主要就是处理了
获取get参数
获取post数据
请求路径余文件的关系。
请求示例
普通请求
返回前端一个 json 对象的请求。
查看示例: user/login.js
静态资源请求
请求一个服务器中的静态资源,并不是下载。比如:头像文件存放在服务器中,我们显示头像并不需要下载下来显示。
查看示例:static/index.js
上传文件
获取前端上传的文件,存放在服务器中。
查看示例:uploadFile/index.js
下载文件
前端下载服务器中的文件。
查看示例:downLoad/index.js