简体   繁体   English

如何在WSO2 ESB上发布现有API

[英]How to publish an existing API on WSO2 ESB

I can't seem to find a simple article on how to publish an existing restAPI through WSO2 ESB as proxy. 我似乎找不到关于如何通过WSO2 ESB作为代理发布现有restAPI的简单文章。

I have an existing API which responds with either Json or XML output based on content-type on the header. 我有一个现有的API,它根据标头上的内容类型用Json或XML输出进行响应。 I would like to publish this api through the WSO2 ESB as proxy. 我想通过WSO2 ESB作为代理发布此api。 I don't think WSO2 Application server is needed in this case, as the rest api is running on its own app server. 我认为在这种情况下不需要WSO2应用服务器,因为其余api在其自己的应用服务器上运行。

API: http://somehost.com:8001/api/BusinessApi/GetContentTypes API: http : //somehost.com : 8001/ api/ BusinessApi/GetContentTypes

Response: 响应:

[{"contentTypeID":1,"name":"Movies","isTop":true,"subLevels":1,"contentTypeIdBase":1},{"contentTypeID":2,"name":"TV Show","isTop":true,"subLevels":3,"contentTypeIdBase":4},{"contentTypeID":3,"name":"TV Season","isTop":false,"subLevels":2,"contentTypeIdBase":4},{"contentTypeID":4,"name":"TV Episode","isTop":false,"subLevels":1,"contentTypeIdBase":4},{"contentTypeID":5,"name":"Music Album","isTop":true,"subLevels":2,"contentTypeIdBase":6},{"contentTypeID":6,"name":"Music Track","isTop":false,"subLevels":1,"contentTypeIdBase":6},{"contentTypeID":7,"name":"Music Video","isTop":false,"subLevels":1,"contentTypeIdBase":7},{"contentTypeID":8,"name":"Book Set","isTop":false,"subLevels":1,"contentTypeIdBase":8},{"contentTypeID":9,"name":"Books","isTop":true,"subLevels":1,"contentTypeIdBase":9}]

The objective is to publish the api via WSO2 ESB and try to achieve the below actions: 目的是通过WSO2 ESB发布api,并尝试实现以下操作:

  1. Logging the API calls 记录API调用
  2. Messaging/ forking calls based on a criteria 基于条件的消息/分叉呼叫
  3. Centralize all API calls authentication model 集中所有API调用身份验证模型
  4. Is it possible to just run ESB server to achieve this function? 是否可以仅运行ESB服务器来实现此功能?

Thanks in Advance!! 提前致谢!!

Setting up a proxy API, this can only be done via 设置代理API,只能通过以下方式完成

  1. adding API option under main->service-bus->APIs 在main-> service-bus-> APIs下添加API选项
  2. Give the API a custom name, which is the identity on WSO2 ESB. 为API指定一个自定义名称,该名称是WSO2 ESB上的标识。
  3. Give the context which is your custom resource. 提供上下文,这是您的自定义资源。
  4. go to the source view and add the below source 转到源代码视图并添加以下源代码

Begin of snippet 摘要的开头

<api xmlns="http://ws.apache.org/ns/synapse" name="GetC" context="/api1">
   <resource methods="GET" url-mapping="/">
      <inSequence>
         <log/>
         <send>
            <endpoint>
               <address uri="http://somehost.com:8001/api/businessApi/GetContentTypes"/>
            </endpoint>
         </send>
      </inSequence>
      <outSequence>
         <log/>
         <send/>
      </outSequence>
   </resource>
</api>

End of snippet 摘要结束

You should now be to access the api via ESB proxy url 您现在应该通过ESB代理URL访问api

With your approach, you have created an api in ESB, which passes the request to your backend api. 使用您的方法,您已经在ESB中创建了一个api,它将请求传递给您的后端api。 During this you expect to log every api call and control authentication too. 在此期间,您还希望记录每个api调用并控制身份验证。 I didn't understand the forking requirement. 我不了解分叉的要求。

Have you tried WSO2 API Manager ? 您是否尝试过WSO2 API管理器 It will allow you to make your api a managed api. 它将使您可以将api设为托管api。 ie You will be able to control access to your api via oauth tokens. 即,您将能够通过oauth令牌控制对api的访问。 You can log the api calls too (although its not a good thing to log every call due to performance reasons). 您也可以记录api调用(尽管由于性能原因,记录每个调用不是一件好事)。

If you integrate it with WSO2 DAS, you will be able to see some useful stats too. 如果将其与WSO2 DAS集成,您还将能够看到一些有用的统计信息。 This is the API Manager documentation. 这是API Manager文档。

https://docs.wso2.com/display/AM1100/WSO2+API+Manager+Documentation https://docs.wso2.com/display/AM1100/WSO2+API+Manager+Documentation

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM