In this video, we demonstrate how you can convert a graphQL query into a REST endpoint.
- Introduction
- Creating the initial REST endpoint
- Creating a Virtual Endpoint
- Modifying headers
Example query:
https://countries.trevorblades.com/
{ countries { name capital currency } }
Virtual endpoint function:
function myTransformerFunction(request, session, config) { varresponseObject = { Body:"THIS IS A VIRTUAL RESPONSE", Code:200 } varresponse = transformationLogic(request) responseObject.Body = response.body returnTykJsResponse(responseObject, session.meta_data) } function transformationLogic(request){ varrequestObj = JSON.stringify({ "method":"POST", "domain":"https://countries.trevorblades.com/", "headers":{"content-type":"application/json"}, "body":JSON.stringify({ "query":"{countries{name, capital, currency}}" }) }) varresponseObj = TykMakeHttpRequest(requestObj) returnJSON.parse(responseObj) }
For more information about Tyk Virtual Endpoints: https://tyk.io/docs/advanced-configur…