Hot reload

See changes in the server immediately after you save.

As API2HTML loads all the templates in-memory during start-up time, changing the content of a template in the disk has no effect in the server. This means that whenever you change the content of a template you need to inform the server that this happened, or restart the server instead.

While we are in development it is very convenient to have an automated system that applies the changes in the server for us. Some options you might consider:

You can start the service under the supervision of a watcher, so whenever a file of your interest changes you restart the service without noticing it. We rely on Reflex for this matter, but you can of course use others.

Install reflex with

go get

And then start the api2html service with reflex:

reflex -r '\.mustache' --start-service -- api2html serve -c config.json

Now, whenever a file with the .mustache extension is changed under this directory (or sub-directories) the service will be restarted, applying all the changes.

If you use multiple sites, docker-compose, the generator or any other system that requires additional steps, adjust reflex at your better convenience.

Make a PUT passing the new content

Another option if you don’t want to use reflex, is to make use of the endpoint for hot reload. You can call it when the service is running with -d and upload the new template to the server. This call is a PUT to the endpoint:

PUT /template/:templateName

And you need to pass:

For instance, let’s update our “home” (home.mustache):

    $ curl -X PUT -F "file=@home.mustache" -H "Content-Type: multipart/form-data" http://localhost:8080/template/home
    'home' uploaded and stored as [home.mustache]!

The command sends the whole file to the service and api2html reloads the template in-memory. You can of course automate this as well.

Continue to Debugging

← Back to Mustache templates