1.5.2 • Published 2 years ago

@prequest/response-types-server v1.5.2

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

@prequest/response-types-server

Restful-API 响应的 JSON 数据的 TypeScript 类型生成器

前言

在前端项目中,没有 fs 等 API,导致不能在运行时,动态生成 Restful-API 响应的 JSON 数据的类型文件。

因而我尝试开发了 @prequest/response-types-generator,它根据配置,可以发起请求和解析响应,最后生成类型文件。但缺点也很明显,需要将要项目中请求的接口一个一个配置到配置文件中。普通的 Get 请求还好说,但对于 Post 请求,一些复杂的传参,也不是很好处理。

本项目解决了上述问题。原理非常简单,首先开启一个 Http Server,然后在前端项目的请求库中间件中,将请求的参数和响应结果,通过一个新的请求实例,发送到 Http Server 中,Http Server 根据传参,利用 fs API 向指定目录生成类型文件即可。

项目分为两部分 @prequest/response-types-server@prequest/response-types-client

安装

npm install @prequest/response-types-server

使用

开启服务器

import server from '@prequest/response-types-server'

// 默认开启的端口为 10086
server()

// 你可以通过传参指定端口
server({ port: 10010 })

生成类型文件

HTTP Server 只接收 POST 与 OPTIONS 请求,当 HTTP Body 传输的数据满足下列参数列表,则会向指定目录输出类型文件

参数类型含义
outPutDirstring类型文件输出目录
outPutNamestring文件名称
overwriteboolean文件可复写
dataJson要解析的 Json 数据
interfaceNamestring导出的接口名称

响应

HTTP Server 只接收到请求后,会返回下列内容

参数类型含义
statusboolean操作成功与否
timestampnumber时间戳
errorError错误信息
datastring[]生成的类型文件列表。前端可根据这个列表,判断是否需要再次发起请求
1.5.2

2 years ago

1.5.1

2 years ago

1.5.0

2 years ago

1.3.7

2 years ago

1.3.6

2 years ago

1.4.1

2 years ago

1.4.0

2 years ago

1.3.10

2 years ago

1.3.9

2 years ago

1.3.8

2 years ago

1.3.5

2 years ago

1.3.3-alpha.0

2 years ago

1.3.3

2 years ago

1.3.2

2 years ago

1.2.6

2 years ago

1.2.4

3 years ago

1.2.1

3 years ago

1.2.0

3 years ago

1.1.4

3 years ago

1.1.3

3 years ago

1.1.2

3 years ago

1.1.1

3 years ago