【问题标题】:Gateway to mask an API end point用于屏蔽 API 端点的网关
【发布时间】:2016-01-20 11:57:42
【问题描述】:

这就是目的,我有关于商业 API 的详细信息以及上面的白标。

之后,我想将其转售给我网站的用户。

将一个 API 重定向到另一个具有相同请求、参数、凭据和响应的最佳方法是什么。

有在线服务吗? 还是使用 Java spring 或 php 的技术示例?

EXAMPLE :

 1. POST, to http://www.commercialapi.com/product/save
{'name': 'customerName', 'nick': 'customerNick'}

 2. DELETE, to http://www.commercialapi.com/product/delete
{'id': 'customerId'}

transform to : 

 1. POST, to http://www.myapi.com/product/save
{'name': 'customerName', 'nick': 'customerNick'}

 2. DELETE, to http://www.myapi.com/product/delete
{'id': 'customerId'}

提前致谢。

【问题讨论】:

    标签: java php spring api swagger


    【解决方案1】:

    我认为 Nginx 是完成这项任务的好方法。您需要在您的域上设置 Nginx 代理。

    尝试使用nginx reverse proxy

    您的任务的示例 Nginx 服务器是:

    server {
        listen 80;
        server_name www.myapi.com;
    
        location / {
            proxy_pass      http://www.commercialapi.com;
            proxy_redirect  http://www.commercialapi.com/ /;
            proxy_read_timeout 60s;
    
            # Your can customize headers as well.
            proxy_set_header          X-Real-IP       $remote_addr;
            proxy_set_header          X-Forwarded-For $proxy_add_x_forwarded_for;
        }
    }
    

    【讨论】:

    • 与 HAProxy 相同类型的解决方案。您应该考虑将您的客户 ID 作为标头注入下游服务。
    • 感谢您的帮助。我会试试看,它看起来很清楚。我认为第一个 url 应该是:proxy_pass myapi.com。 apache 可以吗??
    • Dassi,第一个网址应该是commercialapi.com,我确定。 Apache 太可怕了,不能仅用作代理... Nginx - 是代理的好习惯,允许您使用 Lua 脚本(指令 access_by_lua)为代理创建访问控制逻辑。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-13
    • 2011-11-16
    • 2015-02-19
    • 1970-01-01
    • 1970-01-01
    • 2010-12-19
    相关资源
    最近更新 更多