What is @backstage/catalog-client?
@backstage/catalog-client is a client library for interacting with the Backstage catalog, which is a centralized service catalog for managing all your software components, APIs, and other entities. It allows you to programmatically interact with the catalog to perform operations such as retrieving entities, adding new entities, and searching for entities.
What are @backstage/catalog-client's main functionalities?
Retrieve Entities
This feature allows you to retrieve all entities from the Backstage catalog. The code sample demonstrates how to create a CatalogClient instance and use it to fetch entities.
const { CatalogClient } = require('@backstage/catalog-client');
const client = new CatalogClient({ discoveryApi });
async function getEntities() {
const entities = await client.getEntities();
console.log(entities);
}
getEntities();
Add New Entity
This feature allows you to add a new entity to the Backstage catalog. The code sample demonstrates how to create a new entity object and use the CatalogClient to add it to the catalog.
const { CatalogClient } = require('@backstage/catalog-client');
const client = new CatalogClient({ discoveryApi });
async function addEntity(entity) {
const response = await client.addEntity(entity);
console.log(response);
}
const newEntity = {
apiVersion: 'backstage.io/v1alpha1',
kind: 'Component',
metadata: {
name: 'my-component',
},
spec: {
type: 'service',
lifecycle: 'production',
owner: 'team-a',
},
};
addEntity(newEntity);
Search Entities
This feature allows you to search for entities in the Backstage catalog based on specific criteria. The code sample demonstrates how to create a query object and use the CatalogClient to search for entities that match the query.
const { CatalogClient } = require('@backstage/catalog-client');
const client = new CatalogClient({ discoveryApi });
async function searchEntities(query) {
const entities = await client.getEntities({ filter: query });
console.log(entities);
}
const query = { kind: 'Component', 'metadata.name': 'my-component' };
searchEntities(query);
Other packages similar to @backstage/catalog-client
kubernetes-client
The kubernetes-client package provides a client for interacting with the Kubernetes API. It allows you to manage Kubernetes resources programmatically, similar to how @backstage/catalog-client allows you to manage Backstage catalog entities. However, kubernetes-client is specific to Kubernetes resources and does not provide the same level of abstraction for software components and APIs as @backstage/catalog-client.
octokit
The octokit package is a client library for interacting with the GitHub API. It allows you to manage GitHub repositories, issues, pull requests, and other resources programmatically. While it provides similar functionality in terms of managing resources, it is specific to GitHub and does not offer the same centralized service catalog capabilities as @backstage/catalog-client.
aws-sdk
The aws-sdk package is a client library for interacting with various AWS services. It allows you to manage AWS resources such as EC2 instances, S3 buckets, and Lambda functions programmatically. While it provides similar functionality in terms of managing resources, it is specific to AWS services and does not offer the same centralized service catalog capabilities as @backstage/catalog-client.
Catalog Client
Contains a frontend and backend compatible client for communicating with the
Backstage Catalog.
Backend code may import and use this package directly.
However, frontend code will not want to instantiate a catalog client directly -
use the @backstage/plugin-catalog-react
package instead, which exports a
catalogApiRef
that can be leveraged like other frontend utility APIs.
Links