[[["わかりやすい","easyToUnderstand","thumb-up"],["問題の解決に役立った","solvedMyProblem","thumb-up"],["その他","otherUp","thumb-up"]],[["わかりにくい","hardToUnderstand","thumb-down"],["情報またはサンプルコードが不正確","incorrectInformationOrSampleCode","thumb-down"],["必要な情報 / サンプルがない","missingTheInformationSamplesINeed","thumb-down"],["翻訳に関する問題","translationIssue","thumb-down"],["その他","otherDown","thumb-down"]],["最終更新日 2025-08-21 UTC。"],[[["\u003cp\u003eApigee allows invoking one API proxy from another, which is useful for reusing code, but it should be done efficiently.\u003c/p\u003e\n"],["\u003cp\u003eUsing \u003ccode\u003eHTTPTargetConnection\u003c/code\u003e or custom JavaScript to invoke one API proxy from another causes extra network hops, increasing latency.\u003c/p\u003e\n"],["\u003cp\u003eInvoking one API proxy from another creates unnecessary network hops because requests are routed through the Router and Message Processor again.\u003c/p\u003e\n"],["\u003cp\u003eProxy chaining using \u003ccode\u003eLocalTargetConnection\u003c/code\u003e is the best practice for invoking API proxies, as it executes within the same Message Processor and avoids network hops.\u003c/p\u003e\n"]]],[],null,["# Antipattern: Invoking a proxy within a proxy using custom code or as a target\n\n*You're viewing **Apigee** and **Apigee hybrid** documentation.\nView [Apigee Edge](https://docs.apigee.com/api-platform/antipatterns/proxy-within-proxy) documentation.*\n\nApigee lets you invoke one API proxy from another API proxy. This feature is useful especially if\nyou have an API proxy that contains reusable code that can be used by other API proxies.\n\nAntipattern\n-----------\n\nInvoking one API proxy from another either using `HTTPTargetConnection` in the target endpoint or\ncustom JavaScript code results in additional network hop.\n\n### Invoke proxy 2 from proxy 1 using `HTTPTargetConnection`\n\nThe following code sample invokes proxy 2 from proxy 1 using `HTTPTargetConnection`: \n\n```world-of-warcraft-toc\n\u003c!-- /antipatterns/examples/2-1.xml --\u003e\n\u003cHTTPTargetConnection\u003e\n \u003cURL\u003ehttps://api-test.example.com/proxy2\u003c/URL\u003e\n\u003c/HTTPTargetConnection\u003e\n```\n\n### Invoke proxy 2 from proxy 1 from the JavaScript code\n\nThe next code sample invokes proxy 2 from proxy 1 using JavaScript: \n\n```gdscript\n\u003c!-- /antipatterns/examples/2-2.xml --\u003e\nvar response = httpClient.send('https://api-test.example.com/proxy2);\nresponse.waitForComplete();\n```\n\n### Code Flow\n\nTo understand why this has an inherent disadvantage, we need to understand the route a request\ntakes as illustrated by the diagram below:\n**Figure 1**: Code flow\n\nAs depicted in the diagram, a request traverses multiple distributed components, including the\nRouter and the Message Processor.\n\nIn the code samples above, invoking proxy 2 from proxy 1 means that the request has to be routed\nthrough the traditional route (Router \\\u003e MP) at runtime. This would be akin to invoking an API\nfrom a client thereby making multiple network hops that add to the latency. These hops are\nunnecessary considering that proxy 1 request has already *reached* the MP.\n\nImpact\n------\n\nInvoking one API proxy from another API proxy incurs unnecessary network hops, that is the\nrequest has to be passed on from one Message Processor to another Message Processor.\n\nBest practice\n-------------\n\n- Use the [proxy chaining](/apigee/docs/api-platform/fundamentals/connecting-proxies-other-proxies) feature for invoking one API Proxy from another. Proxy chaining is more efficient as it uses local connection to reference the target endpoint (another API Proxy).\n\n The code sample shows proxy chaining using `LocalTargetConnection` in your endpoint\n definition: \n\n ```world-of-warcraft-toc\n \u003c!-- /antipatterns/examples/2-3.xml --\u003e\n \u003cLocalTargetConnection\u003e\n \u003cAPIProxy\u003eproxy2\u003c/APIProxy\u003e\n \u003cProxyEndpoint\u003edefault\u003c/ProxyEndpoint\u003e\n \u003c/LocalTargetConnection\u003e\n ```\n\n The invoked API Proxy gets executed within the same Message Processor; as a result, it avoids\n the network hop as shown in the following figure:\n **Figure 2**: Code flow with proxy chaining\n\nFurther reading\n---------------\n\n- [Proxy chaining](/apigee/docs/api-platform/fundamentals/connecting-proxies-other-proxies)"]]