# Tutorial: How to use Target Servers in your API Proxies

**URL:** <https://discuss.google.dev/t/tutorial-how-to-use-target-servers-in-your-api-proxies/17530>\
**Category:** Knowledge Hub\
**Tags:** apigee\
**Created:** [February 6, 2016, 7:06pm UTC](https://discuss.google.dev/t/tutorial-how-to-use-target-servers-in-your-api-proxies/17530 "2016-02-06T19:06:53Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![apininja](https://d3byx8b92xw3lq.cloudfront.net/user_avatar/discuss.google.dev/apininja/32/134364_2.png) [@apininja](https://discuss.google.dev/u/apininja)\
**Post date:** [February 6, 2016, 7:06pm UTC](https://discuss.google.dev/t/tutorial-how-to-use-target-servers-in-your-api-proxies/17530/1 "2016-02-06T19:06:53Z")

</div>

When you deal with API Proxies that have to be deployed in multiple environments target servers can help you with getting the backend URL right. A target server definition is basically a name for a backend URL, and you can set a different URL for each environment. By using target servers you can reference the target server name instead of hard-coding the backend URL directly.

Apigee Edge support defining target servers from the UI, and also through the Management API.

In this [video](https://youtu.be/crnuHAgj9Vo) we show how to create target servers and how to use it in your API Proxy. Also we demonstrate how to do load balancing over target servers.

Creating a target server definition through the Management API looks like this:

```auto
curl -H "Content-Type:text/xml" -X POST -d \
'<TargetServer name="OMDB">
   <Host>www.omdbapi.com</Host>
   <Port>80</Port>
   <IsEnabled>true</IsEnabled>
 </TargetServer>' \
-u username@apigee.com [https://api.enterprise.apigee.com/v1/o/orgname/environments/envname/targetservers](https://api.enterprise.apigee.com/v1/o/orgname/environments/envname/targetservers)

```

To reference the target server in the TargetEndpointHTTPConnection you use this XML snippet:

```auto
<LoadBalancer>
  <Server name="OMDB"/>
</LoadBalancer>
<Path>/</Path>

```

If you would like to use LoadBalancing over multiple target server definitions you simply include an algorithm element and all the target servers:

```auto
<LoadBalancer>
  <Algorithm>RoundRobin</Algorithm>
  <Server name="OMDB1" />
  <Server name="OMDB2" />
  <Server name="OMDB3" />
</LoadBalancer>
<Path>/</Path>

```

The following algorithms are supported for loadbalancing:

1. RoundRobin
2. Weighted
3. LeastConnection
4. MaxFailures

More information about target servers can be found here:

[documentation on the management api](http://docs.apigee.com/management/apis/post/organizations/%7Borg_name%7D/environments/%7Benv_name%7D/targetservers)

[load balancing](http://docs.apigee.com/api-services/content/load-balancing-across-backend-servers)

---

<div class="post-metadata">

**Author:** ![anonymous8](https://avatars.discourse-cdn.com/v4/letter/a/7cd45c/32.png) [@anonymous8](https://discuss.google.dev/u/anonymous8)\
**Post date:** [February 9, 2016, 6:56pm UTC](https://discuss.google.dev/t/tutorial-how-to-use-target-servers-in-your-api-proxies/17530/2 "2016-02-09T18:56:08Z")

</div>

any chance you can expand on this a bit and include some https details?

---

<div class="post-metadata">

**Author:** ![apininja](https://d3byx8b92xw3lq.cloudfront.net/user_avatar/discuss.google.dev/apininja/32/134364_2.png) [@apininja](https://discuss.google.dev/u/apininja)\
**Post date:** [February 9, 2016, 9:41pm UTC](https://discuss.google.dev/t/tutorial-how-to-use-target-servers-in-your-api-proxies/17530/3 "2016-02-09T21:41:03Z")

</div>

For SSL in combination with TargetServers you have two options.

**1. One-way SSL**

This one is easy. Make sure that you set the SSLInfo to enabled. When using a self-signed cert also add the truststore.

```auto
<TargetServer name="target1">
  <Host>www.omdbapi.com</Host>
  <Port>443</Port>
  <IsEnabled>true</IsEnabled>
  <SSLInfo>
    <Enabled>true</Enabled>
    <TrustStore>myTrustStore</TrustStore>
  </SSLInfo>
</TargetServer>

```

**2. Mutual SSL**

For mutual SSL you’ll need to set the ClientAuthEnabled to true and also reference the private key in a keystore and (when using self-signed certs) a truststore in the target server definition.

```auto
<TargetServer name="TargetServer 1"> 
    <IsEnabled>true</IsEnabled> 
    <Host>www.omdbapi.com</Host> 
    <Port>443</Port> 
    <SSLInfo> 
        <Ciphers/> 
        <ClientAuthEnabled>true</ClientAuthEnabled> 
        <Enabled>true</Enabled> 
        <IgnoreValidationErrors>false</IgnoreValidationErrors> 
        <KeyAlias>myKeyStoreAlias</KeyAlias> 
        <KeyStore>myKeyStore</KeyStore> 
        <Protocols/> 
        <TrustStore>myTrustStore</TrustStore> 
    </SSLInfo> 
</TargetServer >

```

For more information on this see here: [http://docs.apigee.com/api-services/content/client-ssl-backend-servers](https://community.apigee.com/articles/17980/%E2%80%8Bhttp://docs.apigee.com/api-services/content/client-ssl-backend-servers)

For information on setting up a TrustStore and KeyStore see [http://docs.apigee.com/api-services/content/keystores-and-truststores](http://docs.apigee.com/api-services/content/keystores-and-truststores)

---

<div class="post-metadata">

**Author:** ![anonymous8](https://avatars.discourse-cdn.com/v4/letter/a/7cd45c/32.png) [@anonymous8](https://discuss.google.dev/u/anonymous8)\
**Post date:** [July 28, 2016, 6:43pm UTC](https://discuss.google.dev/t/tutorial-how-to-use-target-servers-in-your-api-proxies/17530/4 "2016-07-28T18:43:00Z")

</div>

BTW, the doc had the algorithm as “LeastConnection” when it should have been "LeastConnections. The doc has been updated [here](http://docs.apigee.com/api-services/content/load-balancing-across-backend-servers).

Stephen

---

<div class="post-metadata">

**Author:** ![anonymous8](https://avatars.discourse-cdn.com/v4/letter/a/7cd45c/32.png) [@anonymous8](https://discuss.google.dev/u/anonymous8)\
**Post date:** [November 9, 2017, 6:58am UTC](https://discuss.google.dev/t/tutorial-how-to-use-target-servers-in-your-api-proxies/17530/5 "2017-11-09T06:58:14Z")

</div>

Can I use variable in name () instead of some constant value.

---

<div class="post-metadata">

**Author:** ![anonymous8](https://avatars.discourse-cdn.com/v4/letter/a/7cd45c/32.png) [@anonymous8](https://discuss.google.dev/u/anonymous8)\
**Post date:** [January 4, 2023, 4:12pm UTC](https://discuss.google.dev/t/tutorial-how-to-use-target-servers-in-your-api-proxies/17530/6 "2023-01-04T16:12:51Z")

</div>

Why i need to add

Path like this

```auto
<Path>/</Path>

```

Can i do like this ?

```auto
<Path>/test</Path>

```
