Virtual Endpoint

Hi All,

I have installed tyk using docker with quickstart example.

Now, i want to configure some virtual endpoint with JavaScript functions on third API. Because i have to retrieve data from two different other APIs, so third API will not have any target URL, which needs to call only javascript function defined in virtual endpoint.

Can any one guide me to do this.
my folder structure : docker-compose.yml, tyk.conf, pump.conf and setup.sh

Any video for sample usage of JS function for an API definition is appreciated.

AM i missing anything here ? please guide.

Hi,

We have Virtual Endpoint examples on our docs site.

I recommend that you check the “An Aggregate JS Function” section.

Regards,
David

Thanks David,

But, the problem is that, where to add this java-script code? and how to bind with API is not so clear.

“extended_path” where it is available in tyk-dashboard in API definitions.

  • Edit your API definition
  • Click on Endpoint Designer
  • Click Add Endpoint
  • Enter the path for your endpoint and select the HTTP method
  • Select the Virtual Endpoint plugin from the plugins dropdown
  • Expand the Virtual Endpoint section
  • Enter your code into the Code Editor textbox

Hi David,
Yes, I did the same. but no where i find.

API Name: : test
Authentication mode : Open
TargetURL : httpbin.org
Endpoint Designer :
Add endpoint : GET /test/{id} / 1 checked (virtual Path)
JS function to call : simpleVirtual
code :

  function sampleVirtual (request, session, config) {
   log("Virtual Test running")
  
   log("param-1:")
   log(request.Params["param1"])

   var responseObject = {
       Body: "THIS IS A  VIRTUAL RESPONSE",
      Headers: {
        "test": "virtual",
        "test-2": "virtual"
    },
    Code: 200
 }
   return TykJsResponse(responseObject, session.meta_data)   
 }
  log("Virtual Test initialised")

and posted the above same in postman :

http://localhost:8080/test/1 (Response 404)

checking at logs from “docker logs -f tykquickstart_tyk_gateway_1”

No where i found the logs and didn’t get the response.

Appreciated your patience.