[go: nahoru, domu]

Skip to content

APIs Configuration

Thiago da Rosa de Bustamante edited this page Mar 27, 2018 · 3 revisions

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.

Creating an API configuration

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.

List APIs configurations

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

Read an API configuration

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

Update an API configuration

Just edit the config file you retrieved previously and then run the command

treeGatewayConfig apis --update test.yaml

or

treeGatewayConfig apis --update test.json

Remove an API configuration

Run the command:

treeGatewayConfig apis --remove 5a69e1f8cbeed907f6acb328

That will remove the API with id 5a69e1f8cbeed907f6acb328

Clone this wiki locally