Best Practice for Endpoint Handler

Hi Team.

I found that there’s an endpoint designer function that i can add more than 1 endpoints under single api.
for example, when api A url is /test, i can add more than 1 endpoints like /test/foo, test/bar under api A
and these configurations are stored together in 1 API definition

  ...
  "custom_middleware": {
      "pre": [],
      "post": [
        {
          "name": "TestPostRequest",
          "path": "/plugin-source/test11_v4.3.1_linux_amd64.so",
          "require_session": false,
          "raw_body_only": false
        }
      ],
      "post_key_auth": [],
      "auth_check": {
        "name": "",
        "path": "",
        "require_session": false,
        "raw_body_only": false
      },
      "response": [
        {
          "name": "TestResponse",
          "path": "/plugin-source/test11_v4.3.1_linux_amd64.so",
          "require_session": false,
          "raw_body_only": false
        }
      ],
      "driver": "goplugin",
      "id_extractor": {
        "extract_from": "",
        "extract_with": "",
        "extractor_config": {}
      }
    },

   ...

  "extended_paths": {
            "url_rewrites": [
              {
                "path": "/bye",
                "method": "GET",
                "match_pattern": "bye",
                "rewrite_to": "http://host.docker.internal:9090/bye",
                "triggers": []
              },
              {
                "path": "/hello",
                "method": "GET",
                "match_pattern": "/hello",
                "rewrite_to": "http://host.docker.internal:9090/hello",
                "triggers": []
              }
            ],
            "go_plugin": [
              {
                "method": "GET",
                "path": "/test",
                "plugin_path": "",
                "func_name": ""
              }
            ]
          }
        }
    ...

so i have some question about this.

Q1.
Regarding documents I can define body transform per endpoint, but it seems not for custom plugins
So, can i control to apply custom plugin per endpoint?
When I set up custom plugins, I couldn’t decide whether to apply it to each endpoint, and it was applied to the whole.

https://tyk.io/docs/advanced-configuration/transform-traffic/endpoint-designer/

Q2.
How do I apply the go plugin function in API Definition and what is the difference from custom plugin? The hook point cannot be specified in the go plugin configuration, so it is not known when it is performed.
is there any detail about the go plugin, please let me know

https://tyk.io/docs/plugins/supported-languages/golang/#golang-virtual-endpoints

Q3.
When should I use endpoint handler? If there are 3 endpoints in one API, is it better to register five endpoints with one API? Or should I register an independent API for each endpoint?
Is there any best practice to use endpoint handler?

Thanks for your support

This depends on convenience and also what you intend on achieving. For example if there is a requirement of:

  • a pre auth hook for some paths
  • global rate limit needed for some paths

then separating them into individual apis and managing that independently would help since there isn’t support for per-path rate limiting.

The Golang virtual endpoints run after all other endpoint designer middlewares. You can validate this from the codebase. So it should be performed after authentication has passed on the API.

Did the go plugin middleware not work for a path? Did you try putting values for the plugin_path and func_name in the go_plugin property?