Skip to content

FwMotion/simple-browser-rest-client

Repository files navigation

Simple Browser REST Client

1. Overview

A standard webpage that makes use of a generated REST client library. The REST client library is generated by OpenAPI Generator and used directly by inline javascript <script> tags.

This sample webpage does not make use of any Single-Page Application frameworks in effort to stay focused on building and usage of the generated REST library.

2. Jetty Run

To serve the files locally while working on the .HTML file, the following maven command may be issued:

./mvnw jetty:run

3. Details

To generate the REST client library, the following steps are taken:

3.1. Generate REST client library sources

The maven goal openapi-generator-maven-plugin:generate-sources is run. This downloads the OpenAPI specification and generates source targeting ECMA Script Flow

3.2. Install Node and NPM

The next step installs Node and NPM into a project-specific temporary location. This is accomplished using the maven goal of frontend-maven-plugin:install-node-and-npm. All subsequent runs of npm or related commands will use this installation.

3.3. Install REST client library dependencies

The maven goal frontend-maven-plugin:npm is run with the single argument "install". When receiving this command, NPM will automatically download all dependencies required for compiling the REST client library.

3.4. Install Browserify Tool

The maven goal frontend-maven-plugin:npm is run a second time; this time to install the browserify tool for preparing the transpiled library to be used in a web browser.

3.5. Transpile REST client library

With dependencies and tools installed, the frontend-maven-plugin:npm goal is run once again. This execution uses arguments "run build:lib" to call the build script defined in package.json. This script transpiles from ECMA Script Flow into ECMA Script 6.

3.6. frontend-maven-plugin:npx browserify

As the final step, the maven goal frontend-maven-plugin:npx is called to execute the browserify tool. This tool further transpiles and prepares the generated library for execution in web browsers.