Skip to content

Commit f50594f

Browse files
dcs3sppSimon Pearsandyo-tyk
authored
[DX 815] Improve Plugins Overview (#4918)
Thanks @andyo-tyk for review. I have committed review suggestions and will publish --------- Co-authored-by: Simon Pears <[email protected]> Co-authored-by: andyo-tyk <[email protected]>
1 parent 5625ca7 commit f50594f

17 files changed

+845
-157
lines changed
Loading
Loading
Loading
Loading
Loading
Loading
Loading

tyk-docs/assets/img/plugins/plugins_overview.svg

+96
Loading

tyk-docs/content/plugins.md

+103-24
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,115 @@
11
---
2-
date: 2020-06-24T12:59:42Z
3-
title: Custom Plugins
4-
description: "This section explains everything you need to know about plugins. This page gives plugins overview and provides links to the appropriate documentation."
5-
tags: ["tyk plugins", "API Gateway middleware", "Custom middleware", "Custom API request"]
6-
menu:
7-
main:
8-
parent: Tyk Gateway
9-
weight: 80
2+
date: 2024-06-21T12:59:42Z
3+
title: Developing Plugins
4+
description: "This section explains everything you need to know about developing your own plugins. This page gives an overview of plugins and provides links to the appropriate documentation."
5+
tags: ["Plugins", "API Gateway middleware", "Custom middleware"]
106
aliases:
117
- /customise-tyk/plugins/
128
---
139

14-
Tyk supports the use of custom plugins to extend Tyk functionality.
10+
Plugins can be used to customize and enhance the capabilities of your APIs through integration with external services and databases to perform operations such as data transformation, custom authentication, logging and monitoring etc.
1511

16-
Plugins can be executed in the **following order** inside the following areas of the [API Request Lifecycle]({{< ref "concepts/middleware-execution-order" >}}):
12+
When Tyk receives an API request, it works through a [chain]({{< ref "middleware-execution-order" >}}) of processing *middleware* that is configured using the API definition. There are a large number of built-in middleware in the processing chain that are dedicated to performing [client authentication]({{< ref "basic-config-and-security/security/authentication-&-authorization" >}}), [request transformation]({{< ref "advanced-configuration/transform-traffic" >}}), [caching]({{< ref "basic-config-and-security/reduce-latency/caching" >}}) and many other processes before proxying the request to the upstream.
1713

18-
* [Pre (Request) Plugin]({{< ref "plugins/plugin-types/request-plugins" >}})
19-
* [Authentication Plugin]({{< ref "plugins/plugin-types/auth-plugins/auth-plugins" >}})
20-
* [Post-Auth (Request) Plugin]({{< ref "plugins/plugin-types/request-plugins" >}})
21-
* [Post (Request) Plugin]({{< ref "plugins/plugin-types/request-plugins" >}})
22-
* [Response Plugin]({{< ref "plugins/plugin-types/response-plugins" >}})
23-
* [Analytics Plugin]({{< ref "plugins/plugin-types/analytics-plugins" >}})
14+
Tyk's custom plugin facility provides a powerful and flexible way to extend the middleware chain. It allows API developers to write custom middleware, in various programming languages, that can perform additional processing of requests and responses.
2415

25-
### Get Started
26-
Get started with your first custom plugin using our [tutorial]({{< ref "plugins/tutorials/quick-starts/go/quickstart" >}}).
16+
For example, a custom authentication scheme can be implemented and executed on API requests, custom plugins can be used to provide integration with external services and databases, or additional processing can be performed on the response returned from the upstream.
2717

28-
### Plugin Caveats
18+
There are several different stages of the [API request lifecycle]({{< ref "/concepts/middleware-execution-order" >}}) where custom plugins can be attached (or *hooked*) into the middleware chain allowing significant customization to meet your specific requirements.
2919

30-
* They must run as a single process.
31-
* To apply a custom plugin to an API you must modify the API definition and add the plugin information to one of the areas of the API Request Lifecycle mentioned above.
32-
* They must manage API-specific cases in the same process, only one CoProcess will be managed by a Tyk Instance.
20+
Custom plugins are usually referred to by the location where they can be *hooked* into the middleware processing chain as follows:
3321

34-
### Language Support
22+
1. [Pre (Request)]({{< ref "/plugins/plugin-types/request-plugins" >}})
23+
2. [Authentication]({{< ref "/plugins/plugin-types/auth-plugins/auth-plugins" >}})
24+
3. [Post-Auth (Request)]({{< ref "/plugins/plugin-types/request-plugins" >}})
25+
4. [Post (Request)]({{< ref "/plugins/plugin-types/request-plugins" >}})
26+
5. [Response]({{< ref "/plugins/plugin-types/response-plugins" >}})
27+
6. [Analytics (Response)]({{< ref "/plugins/plugin-types/analytics-plugins" >}})
3528

36-
You can write plugins in various languages. Check the [supported-languages]({{<ref "plugins/supported-languages">}}) page for specific details.
29+
30+
---
31+
32+
## Supported Languages
33+
34+
A variety of languages are supported for plugin development:
35+
36+
- [Go]({{< ref "/plugins/supported-languages/golang" >}}) plugins are classed as *native* plugins, since they are implemented in the same language as Tyk Gateway.
37+
- [gRPC]({{< ref "/plugins/supported-languages/rich-plugins/grpc" >}}) plugins are executed remotely on a gRPC server. Tyk Gateway supports plugin development for any gRPC supported language.
38+
- [Javascript JVSM]({{< ref "/plugins/supported-languages/javascript-middleware" >}}) plugins are executed within a JavaScript Virtual Machine (JSVM) that is ECMAScript5 compatible.
39+
- [Python]({{< ref "/plugins/supported-languages/rich-plugins/python/python" >}}) plugins are embedded within the same process as Tyk Gateway.
40+
41+
Check the [supported-languages]({{< ref "/plugins/supported-languages" >}}) page for further details.
42+
43+
---
44+
45+
## How It Works
46+
47+
The diagram below illustrates a high level architectural overview for how Tyk Gateway interacts with plugins.
48+
49+
{{< img src="/img/plugins/plugins_overview.svg" width="500px" alt="plugins overview" >}}
50+
51+
From the above illustration it can be seen that:
52+
53+
- The client sends a request to an API served by Tyk Gateway.
54+
- Tyk processes the request and forwards it to one or more plugins implemented and configured for that API.
55+
- A plugin performs operations (e.g., custom authentication, data transformation).
56+
- The processed request is then returned to Tyk Gateway, which forwards it upstream.
57+
- Finally, the upstream response is sent back to the client.
58+
59+
### Plugin Deployment
60+
61+
There are a variety of scenarios relating to the deployment of plugins for an API, concerning the location of the plugin source code and its associated configuration.
62+
63+
#### Local Plugins
64+
65+
The plugin source code and associated configuration are co-located with Tyk Gateway in the same file system. The configuration is located within the API Definition. For further details please consult [API configuration]({{< ref "/product-stack/tyk-gateway/advanced-configurations/plugins/api-config/overview" >}}).
66+
67+
#### Plugin Bundles (Remote)
68+
69+
The plugin source code and associated configuration are bundled into a zip file and uploaded to a remote webserver. Multiple plugins can be stored in a single *plugin bundle*. Tyk Gateway will download the plugin bundle from the remote webserver and then extract, cache and execute plugins for each of the configured phases of the API request / response lifecycle. For further details on plugin bundles and how to configure them, please refer to the [plugin bundles]({{< ref "plugins/how-to-serve-plugins/plugin-bundles" >}}) page.
70+
71+
#### gRPC Plugins (Remote)
72+
73+
Custom plugins can be hosted on a remote server and executed from the Tyk Gateway middleware chain via gRPC. These plugins can be written in any language you prefer, as they are executed on the gRPC server. You'll configure your API definition so that Tyk Gateway will send requests to your gRPC server at the appropriate points in the API request / response lifecycle. For further details please consult our [gRPC]({{< ref "plugins/supported-languages/rich-plugins/grpc" >}}) documentation.
74+
75+
### Tyk Gateway Configuration
76+
77+
#### Coprocess Plugins
78+
79+
In the context of Tyk, *coprocess* plugins refer to external plugins that run alongside the main Tyk Gateway process. These plugins allow for custom logic to be executed within the API lifecycle without modifying the core gateway. Essentially, *coprocess* plugins act as independent services that communicate with Tyk via APIs, enabling the integration of custom functionality written in various languages such as Python, or any other supported gRPC language.
80+
81+
To enable these coprocess plugins, Tyk Gateway needs to be configured accordingly. This is done in the `tyk.conf` file under the `coprocess_options` section, where the option `enable_coprocess` must be set to `true`:
82+
83+
```json
84+
{
85+
"coprocess_options": {
86+
"enable_coprocess": true
87+
}
88+
}
89+
```
90+
91+
#### Plugin Bundles
92+
93+
If you're using [plugin bundles]({{< ref "plugins/how-to-serve-plugins/plugin-bundles#gateway-configuration" >}}) you'll need to configure Tyk Gateway with the URL of the webserver from which it should download the plugin bundles.
94+
95+
#### Javascript and gRPC Plugins
96+
97+
Please consult the supporting documentation for further details on configuring Tyk Gateway when using [Javascript]({{< ref "plugins/supported-languages/javascript-middleware#enabling-the-javascript-virtual-machine-jsvm" >}}) or [gRPC]({{< ref "plugins/supported-languages/rich-plugins/grpc/write-grpc-plugin#configure-tyk-gateway" >}}) plugins.
98+
99+
---
100+
101+
## Plugin Caveats
102+
103+
- Tyk Gateway manages plugins for each API within the same process.
104+
- For [gRPC plugins]({{< ref "plugins/supported-languages/rich-plugins/grpc" >}}), Tyk Gateway can only be configured to integrate with one gRPC server.
105+
- Javascript plugins only allow Pre and Post Request hooks of the API Request Lifecycle.
106+
107+
---
108+
109+
## Supporting Resources
110+
111+
- Get started with developing first Go plugin using our [tutorial]({{< ref "/plugins/tutorials/quick-starts/go/quickstart" >}}).
112+
- Browse our [supported languages]({{< ref "/plugins/supported-languages" >}}) section for language specific tutorials.
113+
- Browse our [plugins hub]({{< ref "/plugins/plugin-hub" >}}) for resources that showcase how to develop plugins.
114+
115+

0 commit comments

Comments
 (0)