Skip to main content
In this guide, you’ll learn how to build a simple Backstage frontend plugin called advice that fetches random tips from an external API and displays them on an entity page. This pattern applies equally well to any REST or GraphQL API, GitHub integrations, or custom backends.

Overview

The advice plugin will:
  • Provide a full-page route at /advice
  • Expose a reusable AdviceCard component
  • Fetch random advice from the Advice Slip JSON API and render it inside an InfoCard
The image shows a webpage for the "Advice Slip JSON API," detailing how to use the API to get random advice, including HTTP methods, URLs, and descriptions. It also includes a sidebar with various endpoints and objects related to the API.
Every time you open or refresh an entity page, the AdviceCard will display a fresh nugget of wisdom.

1. Scaffold the Plugin

Backstage’s CLI can generate all the boilerplate for you. In your Backstage root directory, run:
When prompted, choose:
Once complete, you’ll have a directory structure like this:
The plugin ID (advice) is used for routing, packaging, and yarn workspace commands.

2. Inspect Generated Files

package.json

routes.ts

Defines a route reference for full-page navigation:

plugin.ts

Registers the plugin and its full-page extension:

ExampleComponent (Placeholder)

Located at plugins/advice/src/components/ExampleComponent.tsx:

3. Register the /advice Route

In your application’s main routing file (e.g. packages/app/src/App.tsx), import and add the AdvicePage:
Now, visiting http://localhost:3000/advice shows your placeholder page.

4. Create the AdviceCard Component

We’ll build a compact card that can be embedded in any entity page.

4.1 Define the Component

Create plugins/advice/src/components/AdviceCard.tsx:
Add an index.ts for easy imports:
The image shows a Visual Studio Code interface with a project directory open, displaying various TypeScript files and folders in the explorer panel. The main editor area is open to an empty index.ts file.

4.2 Expose the Extension

In plugins/advice/src/plugin.ts, add:
Update plugins/advice/src/index.ts to re-export:

5. Embed on an Entity Page

Open packages/app/src/components/catalog/EntityPage.tsx (or your custom entity page) and add:
Reload your app—AdviceCard now appears alongside other overview cards.

6. Style with InfoCard

Swap the <div> for Backstage’s InfoCard for a polished look:
The image shows a webpage from Material UI documentation, specifically about "Card" components, with examples and descriptions of different card types like "Simple Card" and "Outlined Card." The page includes navigation links on the left and a contents section on the right.
Explore Backstage Storybook for pre-built layouts:
The image shows a Storybook interface displaying an "Information Card" component with a subheader and placeholder text. The sidebar lists various layout options, and there are controls for customizing the card's properties.

7. Fetch Live Advice

Integrate Backstage’s API abstraction using useApi and fetchApiRef:
The Advice Slip API may cache responses. To force fresh data on each request, consider appending a timestamp query (e.g. ?timestamp=${Date.now()}).
The image shows a screenshot of a web application interface, likely a developer tool, with a sidebar menu on the left and a main content area displaying component details. On the right, there is a browser developer console with code and logs.

8. Run the Plugin Independently

You can develop the plugin without running the entire Backstage app:
A minimal dev server will launch:
The image shows a webpage with a header titled "Welcome to advice!" and a section displaying an example user list with avatars, names, emails, and nationalities.

Conclusion

You have successfully:
  1. Scaffolded a Backstage frontend plugin
  2. Exposed both a full-page route and a reusable card extension
  3. Styled the component with InfoCard
  4. Fetched live data using useApi and fetchApiRef
  5. Embedded the card on an entity overview page
  6. Ran the plugin independently in development mode
Use this blueprint to build data-driven, reusable components in your Backstage ecosystem. Happy coding!

Watch Video