API Connection
An API Connection represents a connection to an external API service within the Smarter platform.
It encapsulates the necessary configuration and credentials (Smarter Secret) required to interact with the API,
# The api of this platform, whose /api/v1/demos/stackademy/course-catalogue/ is the Stackademy course catalogue.
#
# This file is a template. When a Smarter platform loads this repository, it fills in the two placeholders
# of baseUrl below with its own address, e.g. https://alpha.platform.example.com, or
# http://localhost:9357 in local development, so that the Stackademy ApiPlugin queries the api of its own
# platform. To apply this file yourself, save a copy as a .yaml file with your platform's address in baseUrl.
#
# The course catalogue is password protected: this connection sends its apiKey Secret as a bearer
# token, and the course catalogue accepts the apiKey Secret of the Smarter account's stackademy_catalog_api.
apiVersion: smarter.sh/v1
kind: ApiConnection
metadata:
description: Api connection to this platform's Stackademy course catalogue, /api/v1/demos/stackademy/course-catalogue/
name: stackademy_catalog_api
version: 1.0.0
tags:
- stackademy
- api
annotations:
smarter.sh/stackademy/owner: Stackademy IT
smarter.sh/stackademy/purpose: the course catalogue api, for the Stackademy API advisor
spec:
connection:
baseUrl: ${environment_platform_scheme}://${environment_platform_domain}
timeout: 30
authMethod: token
apiKey: stackademy_catalog_api_key
From connections/api/stackademy-catalog-api.yaml.tpl in the Stackademy example project.
Where baseUrl may point
baseUrl may use https or plain http, on any port, but its host must resolve to public addresses
only, and so must the host of every redirect. A baseUrl on a private network, such as
http://10.0.0.5/, http://localhost:8000/ or the cloud’s instance metadata at
169.254.169.254, is refused before any request is sent, and the plugin’s tool call fails. This
keeps a manifest from making the platform call its own network. An api on a private network must be
published at a public address, behind its own authentication.
In the local environment, localhost and other loopback hosts are permitted as well, so that a
developer’s connection can reach the platform’s own api, e.g. http://localhost:9357, as
Stackademy’s tutorials do.
A redirect to another host doesn’t carry the connection’s Authorization header.
Technical References
Django ORM Model:
smarter.apps.connection.models.ApiConnection