• Home
  • Why Erstwhile?
  • Getting Started
  • Learn Erstwhile
  • API Docs
  • Home
  • Why Erstwhile?
  • Getting Started
  • Learn Erstwhile
  • API Docs
  • API Documentation
  • ErstwhileApp
    • getDebug()
    • getConfig(property)
    • setLayout(layout)
    • getComponent(id)
    • getModel(model)
    • redirect(path, updateHistory: true, scrollTop: true)
    • defer(func, delay: 0, selector: null)
    • openModal(controller, modal, args)
    • setModalAttributes(args)
    • closeModal()
  • ErstwhileComponent
    • getCSS()
    • isHidden()
    • hide()
    • show()
    • setProperty(property, value)
    • getProperty(property)
    • isContainer()
    • initialize()
    • unload()
    • getHTML(innerDom)
    • receiveUpdate(key, value)
    • receiveGlobalUpdate(key, value)
    • getTag()
    • getClassName()
    • prepareAttributes()
  • ErstwhileForm
    • getControl(name)
    • showErrors(response)
    • clearErrors()
    • registerComponent(id)
    • deregisterComponent(id)
    • getValues()
  • ErstwhileControl
    • getKey()
    • getValue()
    • setValue(value)
    • setValid(validFlag, message)
  • ErstwhileLayout
  • ErstwhileTheme
    • getRequires()
    • getCSS(appRootDir, workingDir, themeConfig)
    • getFontFolder(appRootDir)
    • getCSSFolder(appRootDir)
    • getJSFolder(appRootDir)
    • getCSSLinks(rootDir)
    • getScripts(rootDir)
  • ErstwhileController
    • preAction(next)
    • postAction(next)
    • getControllerPath()
    • getRoutes()
  • ErstwhileModel
    • makeRequest(path, params, method: "get", data, headers)

ErstwhileModel

26 views 0

Written by mike
August 4, 2023

ErstwhileModel is the base class for models in Erstwhile.

Of the different parts of the MVC framework, the Model layer is the most flexible. The only strict requirement with models is that they are exported by class name in the file /app/models/model.js, and that any methods on them are called statically. How you store data internally to the models isn’t important to Erstwhile.

If you choose to do things The Erstwhile Way™ you’ll receive some benefits, though.

Typically with web applications, the model layer is used to interact with backend systems. This involves hitting various API endpoints on a server to fetch and update data, authenticate, etc. To ease this process, Erstwhile uses a configuration file to describe the endpoints available to it, structures of entities coming out of the server, as well as certain metadata about how authentication happens.

This file is called description.json.

When working with an Erstwhile-aware backend, this file is published by the server at a known endpoint (during development. It isn’t necessary once the application is in production) and the framework is able to fetch this file and build out its model layer through a command line command. As the API changes, the people maintaining it will keep description.json up to date with the changes, and tell you to rebuild your model when needed.

If you are running an ExpressJS-based backend, there is an npm package called erstwhile-backend you can use to help you get up and running with publishing your description.json. It also includes a handy HTML output version so that you can point developers consuming your API to constantly-updated documentation on what your API offers.

If you don’t have an Erstwhile-aware backend, you can create your own description.json and store it in your /app/config directory, and the model build script will use that instead. To get started, we have a handy description.json builder.

Was this helpful?

Yes  No
Related Articles
  • getControllerPath()
  • getRoutes()
  • postAction(next)
  • preAction(next)
  • makeRequest(path, params, method: “get”, data, headers)
  • ErstwhileController

Didn't find your answer? Contact Us

Previously
getRoutes()
Up Next
makeRequest(path, params, method: “get”, data, headers)

loader

Join our Mailing List     

  • Privacy Policy
  • Terms of Use
  • © 2025 RestlessDev. Made in New Orleans.

Welcome to Erstwhile

Thank you for checking out Erstwhile. We’re just getting started, so if you’d like to keep up with our progress please register now and we’ll let you know when new releases come out.

loader

Email Address*

Name