A Spectro Cloud demo application. This is the API server for the Hello Universe app.
The Hello Universe app includes an API server that expands the capabilities of the application. The API server requires a Postgres database to store and retrieve data. Use the Hello Universe DB container for simple integration with a Postgres database.
A Postman collection is available to help you explore the API. Review the Postman collection to get started.
Ensure Docker Desktop on your local machine is available.
- Use the following command and ensure you receive an output displaying the version number.
docker version
Alternatively, you can install Podman.
- If you are not using a Linux operating system, create and start the Podman Machine in your local environment. Otherwise, skip this step.
podman machine init podman machine start
- Use the following command and ensure you receive an output displaying the installation information.
podman info
The quickest method to start the API server locally is by using the Docker image.
docker pull ghcr.io/spectrocloud/hello-universe-api:1.1.0
docker run -p 3000:3000 ghcr.io/spectrocloud/hello-universe-api:1.1.0
If you choose Podman, you can use the following commands.
podman pull ghcr.io/spectrocloud/hello-universe-api:1.1.0
podman run -p 3000:3000 ghcr.io/spectrocloud/hello-universe-api:1.1.0
To start the API server you must have connectivity to a Postgres instance. Use environment variables to customize the API server start parameters.
The API server accepts the following environment variables.
Variable | Description | Default |
---|---|---|
PORT |
The port number the application will listen on. | 3000 |
HOST |
The host value name the API server will listen on. | 0.0.0.0 |
DB_NAME |
The database name. | counter |
DB_USER |
The database user name to use for queries. | postgres |
DB_HOST |
The hostname or url to the database. | 0.0.0.0 |
DB_PASSWORD |
The database password. | password |
DB_ENCRYPTION |
The Postgres ssl mode behavior to enable. Allowed values are: require , verify-full , verify-ca , or disable |
disable |
DB_INIT |
Set to true if you want the API server to create the required database schema and tables in the target database. |
false |
AUTHORIZATION |
Set to true if you want the API server to require authorization tokens in the request. |
false |
The API can be enabled with authorization which results in all requests requiring an authorization header with a token. An anonymous token is available:
931A3B02-8DCC-543F-A1B2-69423D1A0B94
To enable authorization for the API set the environment variable AUTHORIZATION
to true
.
Ensure all API requests have an Authorization
header with the Bearer token.
curl --location --request POST 'http://localhost:3000/api/v1/counter' \
--header 'Authorization: Bearer 931A3B02-8DCC-543F-A1B2-69423D1A0B94'
Note
Authorization does not apply to the /health
endpoint.
We sign our images through Cosign. Review the Image Verification page to learn more.