Server communication

Server communication

Maquette does not prescribe how you should communicate with the server, but there is one gotcha. You must tell the maquette projector to rerender the DOM when data arrives asynchronously.

Using XMLHttpRequest

First let me show you how this can be done when you use plain XMLHttpRequest

Using fetch

If you want tu use the modern fetch API (Needs polyfilling for IE, Edge and Safari) you can use a function similar to the fetchText function below:

Using a library

Most developers do not use XMLHttpRequest or fetch directly, but use some kind of library. Most libraries provide a hook which is invoked whenever a response arrives. You can use such a hook to call projector.scheduleRender(). I will show how this works with the lightweight promise-based axios library.

More information about scheduleRender can be found in the API documentation.