# proxy

proxy钩子注册到Fireboom中也为一个API，和funciton的区别是：

* 没有出入参定义，可以为任意类型，如非结构化数据或xml数据
* 不支持实时查询

**推荐优先使用function，funciton满足不了的，再用proxy钩子**。

<figure><img src="https://2707494476-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNx22Cp3wzkuW1siRbMwW%2Fuploads%2F1glBoPvCirs2CidefIYI%2Fimage.png?alt=media&#x26;token=38034134-ac18-4d01-9858-f835aa61ae62" alt=""><figcaption><p>proxy API界面</p></figcaption></figure>

具体操作步骤同 [zu-he-shi-api](https://docs.fireboom.io/jin-jie-gou-zi-ji-zhi/han-shu-gou-zi/zu-he-shi-api "mention")

示例代码：

{% code title="custom-go/proxy/ping.go" %}

```go
package proxy

import (
	"custom-go/pkg/base"
	"custom-go/pkg/plugins"
	"net/http"
)

func init() {
	plugins.RegisterProxyHook(ping)
}

func ping(hook *base.HttpTransportHookRequest, body *plugins.HttpTransportBody) (*base.ClientResponse, error) {
	// do something here ...
	body.Response = &base.ClientResponse{
		StatusCode: http.StatusOK,
	}
	body.Response.OriginBody = []byte("ok")
	return body.Response, nil
}
```

{% endcode %}

路由规则：

```http
http://localhost:9991/operations/proxy/[proxy-name]

example:: http://localhost:9991/operations/proxy/ping
```

参考：

* fb-admin：<https://github.com/fireboomio/fb-admin/blob/main/backend/custom-go/proxy/bindmenu.go>
