Skip to content
+

Build your first app

Learn the fundamentals of building with Toolpad by creating a small application.

This guide will walk you through the process of creating a small Toolpad application. You'll use the MUI X Data Grid component to display a list of dog breeds from the Dog API. When you click on the name of a breed, a random photo of the breed will be displayed using the Material UI Image component.

Purpose

This guide is intended to introduce you to the fundamentals of building with Toolpad. By the end, you should be able to:

  • set up a new Toolpad app
  • navigate through your workspace
  • design a page and connect its data

Prerequisites

Make sure to install Node on your system.

Building your first application

Interactive walkthrough of the app building process:

Detailed steps

Create a new app

  1. Create a new application

    npx create-toolpad-app dog-app
    
  2. Start the development server

    cd dog-app
    npm run dev
    

    The Toolpad application editor opens automatically in your browser.

Assemble the UI

  1. Hover over the component library and drag a Data Grid component into the canvas. Now repeat the process and drag an Image component as well. When you're done, the canvas should look like this:
Toolpad editor

The Toolpad editor with components dragged

Fetch data

  1. Click anywhere inside the canvas (except on the components that you just added) to deselect all components.

  2. Locate the Add query button inside the inspector. Press it and choose HTTP request.

Choose HTTP request

The Add query menu

  1. We'll be using the dog API for this tutorial. First give the query a unique name: dogQuery. Then, set https://dog.ceo/api/breeds/list/all as the URL. Click the Preview button to inspect the result of this request, and expand the message object in the response. If all went well, it will look like this:
Fetch URL

The dog API response

  1. To transform the response according to our needs, we choose the Transform tab and enable the Transform response option. Write the JavaScript expression:

    return Object.entries(data.message);
    

    in the editor. Click Preview again to verify the result.

Transform response

The dog API response transformed

Bind data to UI

  1. Save the query and close the query editor. Next, we will bind this data to components on the page. Click the Data Grid component to select it.

  2. Find the rows property in the inspector. Notice that there's a small Bind button to its right. Properties with this button next to them can be bound to state available on the page:

Bind data

The bindable rows property

  1. Click the button to open the binding editor. On the left you'll see a list of all bindable state in the page and on the right there's a code editor that accepts any JavaScript expression.

  2. Use the dogQuery available in the scope as a binding expression.

    dogQuery.data;
    

    save the binding and close the binding editor.

dogQuery.data

The binding editor

  1. If all went well, the Data Grid will now display the data from our query:
Connected data

The data grid with bound data

Make the app interactive

  1. Now, we can make this app interactive by displaying a random image of the selected breed. We'll create another query which reacts to the selection inside the Data Grid component. Deselect all components and click on Add queryHTTP request. Name it "imageQuery" and add a breed parameter in the Parameters section on the bottom:
Breed parameter

Editing imageQuery

  1. Click on the Bind button next to the breed parameter value, and add the following JavaScript expression in the binding editor:

    dataGrid.selection?.[0] ?? 'akita';
    

    This will use the selected value from the Data Grid, and default to the "akita" breed when no row has been selected.

Breed binding

Binding breed to the selected value

  1. Then bind the query URL to the following JavaScript expression:

    `https://dog.ceo/api/breed/${parameters.breed}/images/random`;
    
URL binding

Binding the URL to a JavaScript expression

  1. Save the binding and close the binding editor. Save the query and exit the query editor.

  2. In the canvas select the Image component to view its properties in the inspector. Click on the Bind button next to the src prop to open the binding editor, and bind it to imageQuery.data.message.

Bind image src to Java

Binding the Image src to the query response

  1. Try selecting different rows in the datagrid to see the image update to a random image of the selected breed.
Image changes based on selection

The image changing based on the selected row

Preview the app

  1. Click on the Preview button to see a preview of what your app will look like when deployed:
Preview of app

The preview of our application

  1. That's it! Feel free to browse through the rest of the documentation to know more about what you can do with Toolpad.