The "API" folder Last updated: 23. Nov 2023

Create your custom JSON WEB API by placing JS files that will run server side in the #/API foider.

The #/API folder

Any .JS or .HASH file placed in this folder will automatically run on the server side and the response from JS files will be converted to JSON and returned.

This means if you put any .JS files in this folder they will run server side. Unlike any other folder where they will just be served raw to the front end.

HASH files will execute and return HTML if not .CSS.HASH or .CSS.TXT, etc extensions are specified. Then appropriate mime type will be attempted set by the system.

API functions (read and write)

Because the API functions are not cached on the server an extra set of functions are available when running JS from the API folder. These are here to make it possible to create dynamic web applications that your static frontend (always cached) can access data dynamically from.

This is according to PWA standards.

The extra functions available are:

  • Write data to docly
  • Get current user information
  • Call external API's

From the API you can read values for querystring from the "query" object and "form" object for posted form values.

See functions marked with API only in the JS reference:
https://developers.docly.net/JavaScript/

Caching

API functions are always executed on each call and not cached unlike .hash files in other folders. Which will be cached until any underlying data has changed, where they will be regenerated on demand on the next request.