Clash
  • Clash
  • RESTful API
    • Common
    • Proxies
    • Config
Powered by GitBook
On this page
  • 介绍
  • 如何开启
  • CORS

RESTful API

介绍

RESTful API 是一套控制 Clash 的一个途径,能获取 Clash 中的一些信息,同时也能控制 Clash 内部的配置。

基于 API,可以打造自己的可视化操作部分,也是实现 Clash GUI 的重要组成部分。

如何开启

在 Clash 的配置文件中加入 external-controller 字段,如:

# 监听在 127.0.0.1 的 8080 端口
external-controller = 127.0.0.1:8080

# 你可以加入 secret 进行 API 鉴权
# 鉴权的方式为在 Http Header 中加入 Authorization: Bearer ${secret}
secret = thisisyoursecret

如果不是为了特殊需求,请尽量不要把 API 暴露在 0.0.0.0,如果真的要这么做,一定要加上 secret 进行鉴权

CORS

为了能使 Clash 更加灵活,RESTful API 支持 CORS 让使用者能从浏览器使用 XHR、fetch 调用。

PreviousClashNextCommon

Last updated 6 years ago