HTTP PUT saves a complete new representation for a resource. A client sends the replacement content in the request body; the server stores it and makes that content the resource’s current value. For a single persisted AST, PUT /contents overwrites the JSON file backing that resource. section 7.1 section 7.5
A Save action can serialize the edited AST, stringify it as JSON, and send it with fetch. Set method to PUT and Content-Type to application/json so the server can parse the request body. section 7.5
Saving edited DSL contents
The client sends serialize(state.ast) as JSON to /contents. Express installs express.json with a 1gb limit, reads request.body, writes it to storage, updates the in-memory contents value, and returns an empty response. Reloading the app then retrieves the saved representation with GET. section 7.5 section 7.1
Listing 7.28 Server code to handle PUT requests
const { readContents, writeContents } =
require("./storage") #1
// ...other code...
server.use(express.json({ limit: "1gb" })) #2
server.put("/contents", (request, response) => {
const newContents = request.body
writeContents(newContents)
contents = newContents
response.send()
})
This handler shows the complete server-side path from JSON body parsing through file storage and in-memory replacement. section 7.5







