Multiple middlewares per API

Hi all!

I was wondering what the best plugin choice was for the following use case.

We are proxying a number of API’s, each we different middleware requirements. All of them will need a custom authentication middleware which will be the same across all API’s but others will also need more API specific middlewares.

We would ideally like to build up a set of default middlewares that we can mix and match and add more bespoke ones were needed depending on the API requirements.

We do not want to write a custom middleware per API if we can help it as if we change something within the authentication flow, we would need to update and deploy each bundle again and update each API to use the new bundle.

Is it possible to use multiple custom middlewares within a single API and simply chain them? After looking at the rich plugin docs it looks like you can only supply a single “custom middleware bundle” per API.

Is this correct? If so, does anyone have any suggestions on how we keep our middleware set up as DRY as possible? Or maybe there is another solution such as JS middlewares?

Thanks in advance!

Tom

Just looking at the coprocess tests and it looks like you can actually use multiple middlewares.

Are my findings correct? (Hoping they are :grin:)

https://github.com/TykTechnologies/tyk/blob/master/coprocess_test.go#L279

Hi Tom, it’s correct that you can only supply a single bundle per API.

Your use case is interesting so we should really consider it a potential feature.

Do you plan to use different languages for each bundle? Or different languages for each part of the chain?

Best.

Hi Matías,

We would be using a single language, probably Python.

This feature would be fantastic. It is manageable for now but I can see it quickly becoming more difficult to keep on top of bundle updates.

If you need any help I’m more than happy to assist where I can.

One other question. Do you have any or know of any example Python middleware bundles that have unit/integration tests? Trying to mock the Tyk dependencies at the moment but if there were any examples on how to test a middleware that would be amazing!

I had a look at the Tyk plugins such as loggly and correlation but they don’t have any tests.

Cheers