Home‎ > ‎articles‎ > ‎

Building a RESTful Server

Building a RESTful server for SQL data takes time.  We put together this summary so you can compare a traditional process with Espresso.

It's perhaps useful to put this into perspective.  Presuming you are using a frameworks that automate the persistence, caching, REST listeners, JSON mapping etc, we imagine a moderate 100 table system will require in excess of 70,000 lines of code using a conventional approach.  Espresso would express this is 1,500 lines.

A useful comparison, but only begins to tell the entire story.  At least as much time is spent in design as coding, which is largely eliminated from requirements capture.  Automatic re-use has a dramatic effect on maintenance since logic changes are automatically re-ordered and applied to all use cases.

 Activity Description Espresso  
 Hardware   Procure machines for DB and REST server, install OS, etc. Not required for a Service, or on-premise appliance
 Define Database Build database (define tables, columns, referential integrity) Still required
 REST Listener Use framework (e.g, Jersey) to listen for REST requests, and supply REST logic as described below Automated
 Build SQL Requests 
 Map JSON/SQL data 
 Ensure reads/changes to data respect security requirements 
 Ensure User/Password is valid, determine authorized roles 
 Inject Security into every read request to filter rows/columns on read (leveraging SQL filtering for to minimize DBMS trips), and protect data on update 
 Multi-table Rest Resource
 To reduce latency 
 Determine data to be returned 
 Build (including Security enforcement) 
 Supply database integrity logic for validations, derivations, and actions such as email or auditing 
 Object Model
 Build an Object Model for Domain Objects (e.g., JPA) to provide accessors for attributes and related data

See the example at the bottom of this page.  Each such object requires appx 200 lines of code (20,000 for our 100 table system)
 Map object retrievals and updates to SQL, with caching for performance and consistency (provided by JPA, hand-coded with jdbc/odbc) 
 Utilize the Object Model as described below 
 Logic Analysis
 Identify Requirements for derivations, validations, actions 
 Logic Design
 Identify Use Cases affected by Requirement (e.g., OrderTotal definition affects inserting Line Items, deleting Line Items, changing Line Item Quantity, and Part Number) 
 Resource Mapping
 Resource / Object Mapping (de-alias, de-project attributes, to re-use Object Model Logic) 
 Code Object Behavior
 Supply logic 

Our experience suggests at least 500 lines of code per table (50,000 for our 100 table system)
 Change Detection
 Build logic to detect changes (e.g., detect change in Line Item Quantity), including intricate multi-attribute changes (e.g., change to LineItem Quantity and Part Number) 
 Change Propagation
 Adjust Order Total, Customer Balance 
 Logic Ordering
 Ensure the Propagation respects logic dependencies (a greater concern during maintenance / iterations) 

Val Huber,
Sep 27, 2013, 9:47 PM