An open API service indexing awesome lists of open source software.

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

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
```