Develop the Tutorial Web UI =========================== Web UI First Steps ------------------ You will develop a simple Next.js\* application that will interact with the Tutorial Server. First, you will develop and test it locally on your computer and then see how to package it in to an edge application later. .. note:: It is not essential to test the application on your own computer if you do not have Node.js\* environment installed. When you are packaging the code at a later stage in the Dockerfile, you will be able to test it then. The application is developed in a single HTML file, which is a good way to get started with a Next.js application. Follow the `Docs `_ page where you can find more details. Ensure `Node.js application `_ version 18 or later is installed on your computer and install Next.js using npm (part of Node.js). .. code:: bash node --version npx create-next-app@latest tutorial-web-ui --ts --yes cd tutorial-web-ui npm add -s axios npx next dev --turbopack This creates all the needed files to run a Client and makes it available on **http://localhost:3000**. Open your web browser to this address to see the default page. The default page will not be what you want, so you will modify the code. Customize the UI ---------------- The default page contains only a link to the Next.js documentation. You will remove this and only add what you need. First, you remove the `app/page.tsx` file and create a new file **app/page.tsx** with the following content: .. code-block:: :linenos: 'use client' import {useEffect, useState} from 'react'; import axios from 'axios'; // Axios Interceptor Instance const AxiosInstance = axios.create({ baseURL: process.env.NODE_ENV === 'development' ? 'http://localhost:8000' : '/api' }); export default function Home() { const [count, setCount] = useState(0); const [greeting, setGreeting] = useState("not yet set"); const [error, setError] = useState(null); useEffect(() => { AxiosInstance.get('/counter') .then(response => { setCount(response.data.count); }) .catch(error => { setError(error.message); }); }, []); useEffect(() => { AxiosInstance.get('/') .then(response => { setGreeting(response.data.message); }) .catch(error => { setError(error.message); }); }, []); return (

{greeting}

Counter

{count}

{error &&

Error: {error}

}
); } While you do not need to understand all the details of the code, it is clear that you are using Axios library to make calls to the Tutorial Server. You are using the `useState` and `useEffect` hooks (from React) to manage the state of the local variables. `Tailwind CSS `_ is used by default with Next.js, therefore, it is easy to style the page. Verify the UI ------------- To verify the UI, keep the Tutorial Server running in one terminal and start the Next.js application in another with: .. code:: bash npx next dev --turbopack Open your web browser to **http://localhost:3000**. .. figure:: ../images/app-orch-tutorial-web-ui.png :alt: Tutorial Web UI with browser tools .. note:: The browser tools are open in the image above, showing the network requests and the console output. This is an essential tool to understand the requests that are going between your browser and the Tutorial Server. While your browser is still open, run the **curl** commands from the Tutorial Server page. This allows you to see that requests from the UI are equivalent to those from the command line, and that the UI is updating the counter as expected when the buttons are clicked. Next Steps ---------- You can now package the Tutorial Web UI and Tutorial Server into a Container image, so you can deploy them to the edge.