-
Notifications
You must be signed in to change notification settings - Fork 43
APIs Configuration
The gateway configurations are persisted inside the redis database and can be altered through the Admin REST API, Node SDK or CLI tool.
Lets show here how to manage APIs into the gateway using the CLI tool.
To configure an API under the gateway, you need to create a configuration file. You can configure it using YAML or JSON. For example, lets create a file called test.yaml:
---
name: Test
version: 1.0.0
path: "/test"
proxy:
target:
host: http://httpbin.org
timeout: five seconds
And use the Tree Gateway CLI to configure it into the gateway:
treeGatewayConfig apis --add ./test.yaml
And its done. You can test it accessing in your browser: http://localhost:8000/test/get
If you open your test.yaml file, you will see that an ID was added to the configuration. This ID is created if you do not provide one in your configuration.
---
name: Test
version: 1.0.0
path: "/test"
proxy:
target:
host: http://httpbin.org
timeout: five seconds
id: 5a69e1f8cbeed907f6acb328
Take a look at ApiConfig to learn more about the api configuration file.
To see the APIs configured, use the CLI as:
treeGatewayConfig apis --list
If you want to filter the results, you can add those filters to the command. Ex:
treeGatewayConfig apis --list name:test
Only configurations that has a name starting with test
will be listed.
You can add more filters:
treeGatewayConfig apis --list name:test version:1.0.0
To retrieve a configuration for a given API, run the command:
treeGatewayConfig apis --get 5a69e1f8cbeed907f6acb328 > test.yaml
That command will retrieve the configuration for the API with the id 5a69e1f8cbeed907f6acb328
and save it to the file test.yaml.
if you prefer to export the configuration as json, run:
treeGatewayConfig apis --get 5a69e1f8cbeed907f6acb328 json > test.json
Just edit the config file you retrieved previously and then run the command
treeGatewayConfig apis --update test.yaml
or
treeGatewayConfig apis --update test.json
Run the command:
treeGatewayConfig apis --remove 5a69e1f8cbeed907f6acb328
That will remove the API with id 5a69e1f8cbeed907f6acb328