Skip to main content

Javascript React UI with REST HTTP Call

🕓 40 minutes

What you’ll learn

In this tutorial, we will create a simple Javascript React component with Javascript React scaffolder as an SPA (single page application). We want to show a very simple UI with the input field for the username, call ClientInfoService endpoint and show the retrieved information to UI.


Project source

This example project can be cloned from:



Open your IDE, import created component and start coding:

  • Modify main file App.js and replace the content with the following code

    import React, { Component } from 'react'
    import './App.css'

    class App extends Component {
    constructor() {
    this.state = {
    username: 'mkomar',
    data: {roles: []}

    this.handleSubmit = this.handleSubmit.bind(this);
    this.handleChange = this.handleChange.bind(this);

    handleSubmit(event) {
    // console.log(this.state);

    fetch(window.env.CLIENT_INFO_SERVICE_URL + this.state.username)
    .then(resp => resp.json())
    .then(data => {
    if (data[0] !== undefined) {
    this.setState({data: data[0]});


    handleChange(event) {
    this.setState({ username: });

    render() {
    return (
    <div className='container'>
    <br />
    <form onSubmit={this.handleSubmit}>
    <input type="text" size="10" maxLength="10" value={this.state.username} onChange={this.handleChange} />
    <input type="submit" value="Check" />
    <br />
    <p><label><strong>Firstname:</strong> {}</label></p>
    <p><label><strong>Surname:</strong> {}</label></p>
    <p><label><strong>Birth date:</strong> {}</label></p>
    <p><label><strong>Authorization roles:</strong> { ? : ''}</label></p>
    export default App;
  • Next, edit the file config/runtime-configuration.js and add the configuration for server URL

    • note that URL should be different depending on your implementation of the ClientInfoService tutorial example (see Micronaut REST client/server )

      //This is an example configuration for local development, it will be replaced by configurations for individual environments.

      //define all configuration properties under window.env
      window.env = {
  • You are ready to go now. Try to start your application using the terminal command npm start and go to the browser URL http://localhost:3000


What’s next?

If your code works in local development, you are ready to push your changes to GIT and try to build and deploy your new component version to the CodeNOW environment. For more information, see Application Deployment and Monitoring.