liveBook · Manning

REST

As explained in Building User-Friendly DSLs

A REST API is an HTTP-based interface whose resources and operations follow the constraints and conventions of Representational State Transfer.

REST provides an HTTP interface for persisting and transporting application data through resources. A simple backend exposes one resource, /contents, mapped to a persisted JSON file. section 7.0 section 7.1

A minimal REST API can define each operation through the resource URL and HTTP method:

  • GET /contents returns the current JSON contents in the response body. section 7.1
  • PUT /contents replaces the persisted contents with the new JSON supplied in the request body. section 7.1
  • A frontend client retrieves the resource and saves changes through the backend rather than keeping the AST only in memory. section 7.0

Persisting an AST

An Express server can load contents from storage, respond to GET /contents with JSON, and listen on port 8080. The frontend fetches http://localhost:8080/contents, parses the response as JSON, and places the result into application state. Serializing an AST makes it suitable for storage and HTTP transport; deserializing reconstructs it for use by the frontend. section 7.0 section 7.1

Figure 7.1 Architecture of the frontend and backend for implementing AST persistence
figure

Shows the frontend-backend arrangement used to persist and transport AST data. section 7.0

How Building User-Friendly DSLs covers it

How deep it goes
Implements one resource with GET and PUT, then defers broader API complexity while addressing JSON storage and AST references.
Examples
Demonstrates /contents, a persisted contents.json file, Express handlers, frontend fetch calls, and a serialized Rental AST.
What it assumes
Assumes a frontend AST editor and introduces backend storage, JSON serialization, HTTP transport, and deserialization incrementally.
What you can do after
Builds a minimal Express REST API that reads and writes JSON, then connects a frontend client to its resource.
How it connects
Connects HTTP, JSON serialization, deserialization, AST persistence, frontend-backend architecture, and observable application state.

Also explained in

Compare how 22 books explain REST →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Building User-Friendly DSLs. The section links point to the parts of the book it draws on.