ApiProxy:专治不支持跨域访问的 Web API

ApiProxy

Allow Web apps to call APIs by adding Cross-Origin Resource Sharing(CORS) support for them.

+---------+          +-----------+         +---------+
|         | +------> |           | +-----> |         |
| Web App |          | API Proxy |         | Web API |
|         | <------+ |           | <-----+ |         |
+---------+   CORS   +-----------+         +---------+

Usage

The APIs can be configured in config.toml
file usingTOML syntax.

API url is a template string defined by RFC6570 – URI Template
, for example:

[Api.GetIpInfo]
url = "http://ip.taobao.com/service/getIpInfo.php{?ip}"
params = ["ip"]
format = "json"

is converted to:

http://ip.taobao.com/service/getIpInfo.php?ip=127.0.0.1

by given:

http://your.proxy.ip.or.domain/GetIpInfo?ip=127.0.0.1

Run code

pacman -S rustup
rustup install nightly
rustup default nightly
cargo run

Build and run docker image

git clone https://github.com/emk/rust-musl-builder.git
cd rust-musl-builder
docker build --build-arg TOOLCHAIN=nightly -t rust-musl-builder .
alias rust-musl-builder='docker run --rm -it -v "$(pwd)":/home/rust/src rust-musl-builder'
cd ApiProxy
rust-musl-builder cargo build --release
docker build -t apiproxy .
docker run -v "$(pwd)/config":/ApiProxy/config -p 6767:6767 apiproxy

Pull from docker hub

docker pull liujf/apiproxy

原文 

https://github.com/J-F-Liu/ApiProxy

本站部分文章源于互联网,本着传播知识、有益学习和研究的目的进行的转载,为网友免费提供。如有著作权人或出版方提出异议,本站将立即删除。如果您对文章转载有任何疑问请告之我们,以便我们及时纠正。

PS:推荐一个微信公众号: askHarries 或者qq群:474807195,里面会分享一些资深架构师录制的视频录像:有Spring,MyBatis,Netty源码分析,高并发、高性能、分布式、微服务架构的原理,JVM性能优化这些成为架构师必备的知识体系。还能领取免费的学习资源,目前受益良多

转载请注明原文出处:Harries Blog™ » ApiProxy:专治不支持跨域访问的 Web API

分享到:更多 ()

评论 0

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址