Using the Internal Endpoint middleware with Tyk OAS APIs
Last updated: 3 minutes read.
The Internal Endpoint middleware instructs Tyk Gateway not to process external requests to the endpoint (which is a combination of HTTP method and path). Internal requests from other APIs will be processed.
When working with Tyk OAS APIs, the middleware is configured in the Tyk OAS API Definition. You can do this via the Tyk Dashboard API or in the API Designer.
If you’re using the legacy Tyk Classic APIs, then check out the Tyk Classic page.
Configuring the middleware in the Tyk OAS API Definition
The design of the Tyk OAS API Definition takes advantage of the operationId
defined in the OpenAPI Document that declares both the path and method for which the middleware should be added. Endpoint paths
entries (and the associated operationId
) can contain wildcards in the form of any string bracketed by curly braces, for example /status/{code}
. These wildcards are so they are human readable and do not translate to variable names. Under the hood, a wildcard translates to the “match everything” regex of: (.*)
.
The internal endpoint middleware (internal
) can be added to the operations
section of the Tyk OAS Extension (x-tyk-api-gateway
) in your Tyk OAS API Definition for the appropriate operationId
(as configured in the paths
section of your OpenAPI Document).
The internal
object has the following configuration:
enabled
: enable the middleware for the endpoint
For example:
|
|
In this example, two endpoints have been defined:
- the internal endpoint middleware has been configured for requests to the
GET /anything
endpoint - the URL rewrite middleware has been configured for requests to the
GET /redirect
endpoint
Any calls made directly to GET /example-internal-endpoint/anything
will be rejected, with Tyk returning HTTP 403 Forbidden
, since the /anything
endpoint is internal.
Any calls made to GET /example-internal-endpoint/redirect
will be redirected to GET /example-internal-endpoint/anything
. These will be proxied to the upstream because they originate from within Tyk Gateway (i.e. they are internal requests) - so the response from GET http://httpbin.org/anything
will be returned.
The configuration above is a complete and valid Tyk OAS API Definition that you can import into Tyk to try out the internal endpoint middleware.
Configuring the middleware in the API Designer
Adding the Internal Endpoint middleware to your API endpoints is easy when using the API Designer in the Tyk Dashboard, simply follow these steps:
Step 1: Add an endpoint
From the API Designer add an endpoint that matches the path and method to which you want to apply the middleware.
Step 2: Select the Internal Endpoint middleware
Select ADD MIDDLEWARE and choose the Internal middleware from the Add Middleware screen.
Step 3: Save the API
Select SAVE API to apply the changes to your API.