https://github.com/zeromicro/goctl-restclient
Generate Visual Studio Code REST Client plugin files for zero-api
https://github.com/zeromicro/goctl-restclient
Last synced: 4 months ago
JSON representation
Generate Visual Studio Code REST Client plugin files for zero-api
- Host: GitHub
- URL: https://github.com/zeromicro/goctl-restclient
- Owner: zeromicro
- Created: 2022-05-12T13:54:05.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2022-05-13T07:36:26.000Z (over 3 years ago)
- Last Synced: 2025-03-26T08:04:05.574Z (10 months ago)
- Language: Go
- Size: 33.2 KB
- Stars: 3
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## 1. Main Features
* 根据 api 文件生成 [REST Client](https://marketplace.visualstudio.com/items?itemName=humao.rest-client) 所需要的rest文件
* 支持 api default 即默认值
* POST,PUT 暂仅支持json请求结构体
## 2. Installation
通过如下命令安装:
```shell
GO111MODULE=on GOPROXY=https://goproxy.cn/,direct go install github.com/zeromicro/goctl-restclient
```
## 3. 快速开始
* 1.create the API file, like user.api,
```go
type (
//注册请求结构
RegisterReq {
Username string `json:"username,default=admin"`
Password string `json:"password,default=admin123"`
Mobile string `json:"mobile"`
}
LoginReq {
Username string `json:"username"` //测试
Password string `json:"password"`//测试2
}
UserInfoReq {
Id string `path:"id"`
}
UserInfoReply {
Name string `json:"name"`
Age int `json:"age"`
Birthday string `json:"birthday"`
Description string `json:"description"`
Tag []string `json:"tag"`
}
UserSearchReq {
KeyWord string `form:"keyWord"` // 关键词
}
)
service user-api {
@doc(
summary: 注册
)
@handler register
post /api/user/register (RegisterReq)
@doc(
summary: 登录
)
@handler login
post /api/user/login (LoginReq)
@doc(
summary: 获取用户信息
)
@handler getUserInfo
get /api/user/:id (UserInfoReq) returns (UserInfoReply)
@doc(
summary: 用户搜索
)
@handler searchUser
get /api/user/search (UserSearchReq) returns (UserInfoReply)
}
```
* 2. Generate REST client file
```shell
goctl api plugin -plugin goctl-restclient="-filename user.rest" -api user.api -dir .
```
* 3. Request Variables
- touch .env
```shell
baseUrl = http://127.0.0.1:8921
```