Configuring Multiple different backend

Is it possible for TYK gateway to forward the incoming request to the different backend end point using same API definition and listening PATH. If its possible then how can we do that.

Hello @saloni512,

That is possible through a the batch request method in tandem with the virtual endpoint. Here is an example.

Can you help me understanding in better way with below use case:

Listen path is fixed: /CloudGateway/rest/

Target URI1: https://60n5waqkgk.execute-api.ap-southeast-1.amazonaws.com /CloudGateway/rest/

Target URI2: https://ot22h0x8q5.execute-api.ap-southeast-1.amazonaws.com/test/CloudGateway/rest/

Then how do I configure at the tyk side So that it should generate unique url for each callback url with the same listen path.

As I am doing POC on open source TYK Gateway So the same feature is available with open source?

Yes this same feature is available in the open source version

Honestly, it is not clear what you are asking.
You can configure Tyk to proxy based off Hostname OR listen path.

ie:

https://myapi.mycompany.com → goes to some API A
https://myapiB.mycompany.com → goes to some API B

https://myapi.mycompany.com/myAPI → goes to some API A
https://mycompany.com/myAPIB → goes to some API B

Does this help?

If you have an architecture diagram, it can probably eliminate some of the language barrier

1 Like

HI Sedky,

Below is flow diagram of the scenario, hope it clarifies:

Here:

  1. There will be only 1 TYK open source server.
  2. Listen path is going to be common for multiple apps so is TYK is capable to generate unique url for each API with the same listen path which is going to be /CloudGateway/rest/
  3. Bakend (Target URI) can be same or different.

Please let me know If you need more clarification.

Yes, this is completely supported, you’re describing Host Header based routing.

You can set the “domain” field in the API definition and Tyk will route based off that.

ie:
API Def 1

...
"domain": "my-api-1.com",
"listen_path": "/test/",
"proxy": {
    "target_url": "hostname1.com",
    "strip_listen_path":"false"
}

That means API request to Tyk at http(s)://my-api-1.com/test/ will be reverse proxied to http(s)://hostname1.com/test/

And that can live alongside API def 2 with a different domain/subdomain.

...
"domain": "my-api-2.com",
"listen_path": "/test/",
"proxy": {
    "target_url": "hostname2.com",
    "strip_listen_path":"false"
}

Does this make sense?

I got it, but how do we setup multiple domanins for 1 TYK servers any input on that?

I have created 1 API with below definition;

curl -v -H “x-tyk-authorization: 352d20ee67be67f6340b4c0605b044b7”
-s
-H “Content-Type: application/json”
-X POST
-d ‘{
“name”: “cloudgatewaydomain1”,
“slug”: “cloudgatewaydomain1”,
“api_id”: “cloudgatewaydomain1”,
“auth”: {},
“org_id”: “1”,
“use_keyless”: true,
“definition”: {
“location”: “header”,
“key”: “x-api-version”
},
“version_data”: {
“not_versioned”: true,
“versions”: {
“Default”: {
“name”: “Default”,
“use_extended_paths”: true
}
},
“strip_auth_data”: false
},
“domain”: “my-api-cloudgatewaydomain1.com”,
“proxy”: {
“listen_path”: “/CloudGateway/rest/”,
“target_url”: “https://ip-10-10-31-38.ap-southeast-1.compute.internal:8443”,
“strip_listen_path”: false
},
“active”: true
}’ https://ec2-18-142-155-240.ap-southeast-1.compute.amazonaws.com:8080/tyk/apis --insecure | python -mjson.tool

When I try to access curl https://my-api-cloudgatewaydomain1.com/CloudGateway/rest/, its not working because I think I have not setup the domain my-api-cloudgatewaydomain1.com.

Please suggest here.

Any suggestions here?

Any input here Please

Hi,

You will need to setup the name resolution for my-api-cloudgatewaydomain1.com to reach your gateway. This is a client side thing so you it could be a simple as adding my-api-cloudgatewaydomain1.com to your hosts table with the IP address of your gateway.

You can also use curl to simulate this with something like

curl --resolve my-api-cloudgatewaydomain1.com:8080:18.142.155.240 https://my-api-cloudgatewaydomain1.com:8080/CloudGateway/rest/

Hope that helps.
Pete