Service discovery endpoint

i use service discovery.
i want to make dynamic endpoint query.

make endpoint query with pamameter in request header or request bady

if : http header { test :test }
then : service discovery endpoint query is http://x.x.x.x/eureka/test

how can i define api object?
or other method?

Hi Jell

Can you give the community a bit more info about the scenario? At the moment its not quite clear what you have setup and what you are trying to achieve. Information about the typ of Tyk deployment or SaaS that you are using and the architecture / use-case can be helpful.




we use tyk community editions
we have 6 service on 6 diffrent networtk envirment
and they are individually registered in eureka. ( using each different name)

tyk request header contain network info from client

when recive the request
we want to select service by using header info(only one listen path).

but when we define api

it seems like service discovery query_endpoint is fixed so no modification allowed

so we use middleware and try it
we gain service info from service discovery server with Tykbatchrequest function
but with this info we cannot change target url(selected service)

follow middleware js
// ---- Sample middleware creation by end-user -----
var samplePostProcessMiddleware = new TykJS.TykMiddleware.NewMiddleware({});

samplePostProcessMiddleware.NewProcessRequest(function(request, session) {

	// Batch request
	var batch_toServiceDiscovery = {
		"requests": [
				"method": "GET",
				"headers": {
					"x-tyk-test": "1",
					"x-tyk-version": "1.2",
					"authorization": "1dbc83b9c431649d7698faa9797e2900f"
				"body": "",
				"relative_url": "http://x.x.x.x:8761/stackService-Test" // change url with header info
		"suppress_parallel_execution": false

	var result_serviceDiscovery = TykBatchRequest(JSON.stringify(batch_toServiceDiscovery));

	var asJS = JSON.parse(result_serviceDiscovery)

	for (var i in asJS) {
		asJS[i].body = JSON.parse(asJS[i].body)
   // i don't know next step... using this info

    return samplePostProcessMiddleware.ReturnData(request, {});

log("Sample POST middleware initialised");

give me some advice on this problem

when define api
Is there any way we can set out query_endpoint manually?
or is there any other way to solve this problem? (ex. by using middleware)


From what I understand, you want to change the service discovery URL in the API definition based on a request header.

Unfortunately, those values are fixed in the gateway on load, there’s no mechanism to change the service discovery URL dynamically based on a header value, not even with middleware.

Sorry I can’t be more helpful here, but its not something that Tyk can do for you!

can each service have unique listpath?

in this case for slove problem with tyk.
we have different listen path. like http://localhost/{service}/resource

in middleware can’t we change target url? never…?


Hi Jell

Changing the target URL is possible with the URL Rewriter.
(it maybe also possible through custom middleware - but that has not been tested, so you’ll have to experiment)