This chapter covers
- Implementing a simple Web backend with a REST API for basic persistence of an AST
- Serializing an AST to JSON
- Deserializing an AST from its serialized JSON form
- Fixing the reference problem we encountered in chapters 5 and 6
In chapters 4 through 6, we learned how to create a projectional editor for domain experts to visualize and edit DSL content that’s represented as an AST. We didn’t implement any persistence for that DSL content, so far. The AST that our editor works on only exists on the frontend. It’s constructed in-memory by code that’s part of the bundled frontend code. When the AST is altered, the changes aren’t stored.
In this chapter, we’re going to implement AST persistence. First, we’re going to implement an extremely simple REST Web backend, which is going to store one (1!) JSON file on disk. (The implementation will be as simple as possible—maybe even naive.) This might seem limiting, but it suffices for our purposes, and keeps things simple. Frontends can GET
this JSON file, and also PUT
a new version of it, which replaces the previous version on disk.