Hi all, I want to know how to
- Integrate the backend api definition(the actual API implementation) with tyk API gateway
- Verify the client request reaching tyk API gateway is forwarded to the backend API implementation
Thanks
Nagaraj Trivedi
Hi all, I want to know how to
Thanks
Nagaraj Trivedi
Hi @NagarajTrivedi, it depends on the type of API your backend is. If you have downloaded and properly setup the tyk-demo with the Tyk Dashboard, then you can simply follow these tutorials below
REST API Demo
GraphQL API Demo
Hi Olu, I tried installing the tyk-demo but it asks for the license value should be assigned to the dashboard license.
DASHBOARD_LICENCE=<YOUR_LICENCE>
Please let me know what value I need to enter
From the file README.md with the link GitHub - TykTechnologies/tyk-demo: Tyk Docker Demo with full Pro Tyk Installation and more!
In step 3 : Add Docker Environment variables
The tyk/docker-compose.yml
and tyk2/docker-compose.yml
files use a Docker environment variable to set the dashboard licence. To set this, create a file called .env
in the root directory of the repo, then set the content of the file as follows, replacing <YOUR_LICENCE>
with your Dashboard licence:
DASHBOARD_LICENCE=<YOUR_LICENCE>
Please clarify with value <YOUR_LICENCE> should be replaced
Thanks
Nagaraj
As Andrew mentioned on this post, you would need a 14 day trial access. This is because the dashboard is closed source.
You can evaluate the open source gateway without the dashboard. You just need to install redis and have it running on port 6379 and then compile the gateway.
In your first post, I can see that you have already done that. Running the binary executable file that was compiled will bind it to your localhost by default. You can confirm the gateway is working with this endpoint http://localhost:8080/hello
If redis is not connected then you would see the fail status message like below
{“status”:“fail”,“version”:“v3.0.0”,“description”:“Tyk GW”,“details”:{“redis”:{“status”:“fail”,“output”:“storage: Redis is either down or was not configured”,“componentType”:“datastore”,“time”:“2021-09-20T10:00:03+01:00”}}}
If redis is connected then you will see a status message like below
{“status”:“pass”,“version”:“v3.0.0”,“description”:“Tyk GW”,“details”:{“redis”:{“status”:“pass”,“componentType”:“datastore”,“time”:“2021-09-20T11:35:57+01:00”}}}
To get redis working, please follow the getting started guide on redis.
After that is done, you can then create API definitions manually or through the Gateway APIs. Please note you would have to map the paths in your tyk config file to local directories. For example mapping app_path in your tyk config
A default config file will be generated for you if none exists when you start the gateway. You can start the gateway by running the command ./tyk start in your OS shell or terminal. FYI, you need to be in the location where your binary file was built for it to work
Hi Olu, I have preferred the opensource method of creating the APIs.
I succeeded in creating and accessing the APIs manually. But when accessed the page “Publish An API” then I found only two options. One is the cloud and the other is Self-Managed.
There is no “Open Source” option.
Let me know how I can publish APIs with open source.
Thanks and Regards
N.M.Trivedi
Hi @NagarajTrivedi, glad to hear that you were successful in creating APIs.
The Publish API section is regarding the Developer Portal which is part of the Dashboard (which requires a license). The Developer Portal is where developers/API consumers can learn about your APIs, request access and even test them to ensure they are performing as advertised.
By default if the active property in an API definition is set to true then you can make calls to that API. The Developer Portal is just a nice web interface to discover and try the APIs.
You can always build your own and link the calls from your web API server.
Hi Olu, thanks for the clarification.
But more clearly what I want to know is how this API definition should be written, linked with tyk gateway, called and tested.
Are there any simple sample programs for it and a step by step procedure to integrate with tyk gateway. If you provide this information then it will be of great help to me. I am in urgent need of this.
Thanks and Regards
N.M.Trivedi
TL;DR
How API Definition should be written => Depends on the property of the API definition
How to call or test your API => { hostname } / { listen_path }
In the API you created, there should be a listen_path property. This is the relative path that identifies your API and also how the gateway knows which API is being called.
By default, your Tyk gateway would be hosted on your localhost at port 8080 (localhost:8080). This is the root path. To make a request to your Tyk created endpoint, you would need to combine the root path with the relative path to form the absolute path.
The absolute path or full endpoint for the API below is http://localhost:8080/http-bin-site.
{
"name": "Http Bin Site",
"use_keyless": true,
"active": true,
"proxy": {
"listen_path": "/http-bin-site/",
"target_url": "http://httpbin.org",
"strip_listen_path": true
}
}
How an API definition is written and created depends on the authentication type, versioning, endpoints and advanced options like CORS, caching, certificates etc. You can peruse the raw API definition here. Or you could call the GET operation on the Tyk gateway (tyk/api or tyk/api/{apiID}) to view an already existing API.
You can simply run the example I have attached above which routes the request to the httpbin.org backend. You can explore the kind of operations that can be performed with httpbin by visiting the website.
Hi Olu, I ran the command straight forward
curl -X GET http://localhost:8080/http-bin-site
But it did not work and displayed the message
Not Found
I also created my own api helloworld2 that was running on the port number 10010
I created a new api helloworld2 with the following configuration on the same machine on which tyk is running
curl -v -H “x-tyk-authorization: 352d20ee67be67f6340b4c0605b044b7”
-s
-H “Content-Type: application/json”
-X POST
-d ‘{
“name”: “helloworld2”,
“slug”: “helloworld2”,
“api_id”: “helloworld2”,
“org_id”: “1”,
“use_keyless”: true,
“active”: true,
“auth”: {
“auth_header_name”: “Authorization”
},
“definition”: {
“location”: “header”,
“key”: “x-api-version”
},
“version_data”: {
“not_versioned”: true,
“versions”: {
“Default”: {
“name”: “Default”,
“use_extended_paths”: true
}
}
},
“proxy”: {
“listen_path”: “/helloworld2/”,
“target_url”: “http://localhost:10010/”,
“strip_listen_path”: true
},
“active”: true
}’ http://localhost:8080/tyk/apis | python -mjson.tool
and it got create with following message
I ran the command
curl -X GET http://localhost:8080/helloworld2
Even then I got the same error message saying Not Found
Let me know where I have done the mistake
Hi @NagarajTrivedi, you would need to ensure you are putting the trailing forward slash (/) in the call as shown in the listen_path. Or you could remove it, save, hot reload and test the call again.
Let me know how it goes.
Hi Olu, it worked.
Thanks
Nagaraj
That’s great!
Happy to help.