REST Datasource
Last updated: 2 minutes read.
The REST Datasource is a base component of UDG to help you add existing REST APIs to your data graph. By attaching a REST datasource to a field the engine will use the REST resource for resolving.
We have a video which demoes this functionality for you.
Using external REST API as a Datasource
In order to use an external REST API as a Datasource you need to first navigate to the field which that Datasource should be attached to.
- Click on the field which should have a datasource attached
- From the right-hand side Configure data source panel choose REST at the bottom in the Add a new external data source section
- Provide data source name, URL, method to be used. Optionally you can add headers information and configure field mapping
- Click the Save & Update API button to persist the configuration and generate a REST resolver, to resolve this field at runtime.
Using Tyk REST API as a Datasource
- Click on the field which should have a datasource attached
- From the right-hand side Configure data source panel choose REST | Tyk dropdown to see all available APIs
- Choose which Tyk REST API you want to attach
- Provide data source name, endpoint and method to be used. Optionally you can add headers information and configure field mapping
- Click the Save & Update API button to persist the configuration and generate a REST resolver, to resolve this field at runtime.
Once done the field you just configured will show information about data source type and name:
Automatically creating REST UDG configuration based on OAS specification
Tyk Dashboard users have an option to use Tyk Dashboard API and quickly transform REST API OAS specification into a UDG config and have it published in the Dasboard within seconds.
See our Postman collections and fork Tyk Dashboard API v5.1
.
The endpoint you need to use is:
POST /api/data-graphs/data-sources/import
Request body:
{
"type": "string",
"data": "string"
}
type
is an enum with the following possible values:
- openapi
- asyncapi
To import an OAS specification you need to choose openapi
.
If you are using Postman and your OAS document is in yaml
format you can use a simple pre-request script to transform it into a string
.
pm.environment.set("oas_document", JSON.stringify(`<your_yaml_goes_here>`))
Then your request body will look like this:
{
"type": "openapi",
"data": {{oas_document}}
}