The Live Web


The Live Web: Building Event-Based Connections in the Cloud (2011) .. by Phil Windley @windley


Table of Contents

Introduction … xix

Chapter 1 The Live Web … 1

Bad News from Your Radiologist … 2

The Live Web … 3

The Evolution of the Web … 4

Document Web … 4

Web 1.0 … 5

Web 2.0 … 5

Live Web … 6

The Cloud and Programmatic Access to Data … 6

The Real-Time Web … 8

Turning the Web Inside Out … 9

Dynamic Queries, Static Data … 9

Dynamic Data, Static Queries … 10

Events … 12

The Evented Web … 12

Please, Interrupt Me … 13

Web Hooks … 13

This Is Getting Personal … 14

Building the Live Web … 15

Endnotes … 16

Chapter 2 Events on the Live Web … 17

Events … 18

Event Semantics … 19

Event Detection … 20

Event Properties … 21

Event Schema … 21

Event Processing … 22

Events on the Live Web … 25

Example 1: Device Automation … 25

Example 2: Social Network Monitor … 25

Example 3: Kid Tracker … 26

Example 4: Personal RFP Service … 26

Example 5: Live Customer Contact Management 27

Example 6: Home Maintenance … 27

Example 7: Groupon Annotation … 27

Example 8: Location-Enabled Merchant Offers 28

Example 9: Home Inventory … 28

Example 10: Personal Relationship Management 29

Live Web Applications … 29

Endnotes … 29

Chapter 3 Event Expressions: Filtering the … 31

Event Stream

Patterns and Filtering … 32

A Pattern Language for Events … 33

Finding Individual Events … 34

Exact Matches … 34

Attribute Matching … 35

Capturing Values … 35

Attribute Expressions … 36

Event Scenarios … 37

Compound Events … 39

Event Operators … 39

Time … 41

Variable Arity Event Operators … 44

Group Operators … 45

Variable Correlation Between Eventexes … 47

Aggregators … 47

Eventex Examples … 48

Example 1: Large Withdrawals … 48

Example 2: Too Many Withdrawals … 48

Example 3: Too Many Withdrawals in 24 Hours 49

Example 4: Too Many Withdrawals over a Limit 49

Example 5: Withdrawal after a Deposit … 49

Example 6: Withdrawal after a Deposit with … 49

a Limit

Example 7: Phone Call with a Follow-Up SMS … 49

Example 8: Too Many Phone Calls … 49

Example 9: Too Many Phone Calls from One … 50

Number

Example 10: Looking at Travel Sites … 50

Example 11: Looking for Support … 50

Example 12: Find News Articles That Affect … 50

Stock Price

Matching Scenarios … 51

Endnotes … 51

Chapter 4 Telling Stories on the Live Web … 53

Me and My Data … 54

User-Controlled Identity … 55

Personal Data … 57

Better Golf Through Software … 57

It’s All Semantics … 58

Purpose and Intent … 59

When to Bind … 60

Coupling … 60

Context and Correlation … 62

Entity Correlation … 63

Explicit Eventex Correlation … 64

Implicit Correlation Through Context … 65

An Example … 67

Impromptu Theater … 69

Endnotes … 69

Chapter 5 Architecting the Live Web … 71

Requirements of the Live Web … 71

Requirements in Action … 72

Practical Considerations … 73

The Kinetic Event Architecture … 73

Endpoints … 75

Raising Events in KEA … 77

Event Examples … 79

Predefined Events … 80

Raising Events with HTTP … 82

URL Encoding Example … 83

Maintaining Context … 84

Responding to Directives … 85

Processing Events … 86

Building an Endpoint … 87

Small Pieces Loosely Joined … 89

Endnotes … 90

Chapter 6 Live Web Rules … 91

Rules for Events … 91

The Kinetic Rule Language … 93

Your First Rule … 94

Rules Are Simply Conditional Actions … 95

Event Attributes, Conditions, and Filters … 97

What Happens When an Event Is Raised? … 98

Taking Action … 99

Compound Actions … 101

Expressions … 102

Comments … 102

Literals … 102

Arithmetic, String, and Boolean Expressions 103

Conditional Expressions … 103

Operators … 104

Event Attributes … 105

Declarations … 105

Functions … 106

Persistent Variables … 108

Using Persistents in Preludes … 108

Using Persistents in Conditions … 109

Mutating Persistents in the Postlude … 110

Using Persistents … 111

Programming in KRL … 113

Why Use the Kinetic Rule Language? … 115

Endnotes … 117

Chapter 7 Creating Contextual Web Experiences … 119

Context and Browsing … 119

Contextual Web Experiences … 120

KRL and the Web … 122

The Web Endpoint … 122

Placing Tags … 123

Using Salience Data … 124

The Web Runtime … 125

Dual-Execution Environment … 127

Web Events … 128

pageview … 128

submit … 129

click and change … 129

Other Event Attributes … 129

Actions in the Web Domain … 130

Examples of KRL in Action on the Web … 132

Welcoming Searchers to My Blog … 132

Search-Result Annotation … 136

Using Web Forms with KRL … 139

Improving the Rule Set … 144

Context Enables the Live Web … 144

Endnotes … 144

Chapter 8 Using the Cloud … 145

dataset and datasource Declarations … 145

dataset Declarations … 146

datasource Declarations … 147

Data Formats … 148

APIs and Built-In Libraries … 149

The HTTP Library … 149

Other Libraries … 153

JSONPath Expressions … 155

Don’t Buy That Book! … 156

Key Management … 159

Example: Showing Tweets on My Blog … 160

Looping in KRL … 161

When to Use a Loop … 163

Loops Drive Multiple Actions … 165

Seeing Your Friend’s Tweets … 167

Authorize-then-Use … 167

Initialize-then-Populate … 169

Abstracting Cloud Services in KRL … 171

User-Defined Actions … 171

User-Defined Modules … 174

A Calendar Module … 176

Using the Cloud … 179

Endnotes … 179

Chapter 9 Events Around the Web … 181

Endpoints … 181

Using Web Hooks and PubSubHubbub … 182

On the Prowl … 183

Building Endpoints … 185

Email … 187

Watching IMAP … 188

Cloud-Based Email Rules … 190

Email Articles to a Blog … 191

Node.js and the Live Web … 192

Building an IRC Bot … 192

An IRC Endpoint … 193

An Evented World … 195

An Arduino-Powered Sprinkler Controller … 197

Building the Live Web … 201

Endnotes … 202

Chapter 10 Mobile and the Live Web … 203

A PBX in the Cloud … 203

Events from Voice … 205

The twilio Library … 205

Extending the TA Rule Set … 208

Using SMS … 210

An Interactive Voice Response System … 212

Handling the Call and Giving the Menu … 212

Handling the Menu Choices … 214

Handling Bad Choices and Cleaning Up … 215

Beyond Voice: Mobile Live Web Applications … 216

Using KRL in Mobile Apps … 217

Going Mobile … 220

Endnotes … 220

Chapter 11 Building Event Networks … 221

Understanding Event Types … 221

Raising Explicit Events in the Postlude … 222

Automatically Raising Events … 223

The Explicit Event Action … 225

Explicit Events as Rule Abstractions … 228

Events and Loose Coupling … 229

Explicit Events for Error Handling … 230

Raising Errors … 230

Handling Errors … 231

Event Intermediaries … 232

Event Intermediary Patterns … 233

Event Logging … 233

Abstract Event Expressions … 234

Event Preprocessing … 234

Event Stream Splitting … 235

Semantic Translation … 236

App Controller Rule Set … 237

Complex Event Scenarios … 239

Explicit Events … 240

Chapter 12 Advanced KRL Programming … 241

A Blog in KRL … 241

Configuring the Blog with the KBlog … 242

Configuration Rule Set

Building the Blog with the KBlog Rule Set … 242

Handling Data with the KBlog Data Rule Set … 247

Posting with the KBlog Post Rule Set … 249

Event Hierarchies … 252

Design Considerations … 253

Making the Back Button Work … 254

Change the URL Fragment … 254

Updating the Page When the Fragment Changes 256

Changes to the Event Hierarchy … 258

An Experiment in Loose Coupling … 258

Tweeting a Post … 259

Making Tweeting Optional … 260

Lessons Learned … 262

Avoid Terminal Rules … 263

Generalize Attribute Passing … 263

Supporting Extensibility … 263

Changing the Event Hierarchy Again … 263

Building Loosely Coupled Applications … 263

Chapter 13 Business on the Live Web … 265

Ignoring the Attention Economy … 266

Privacy Matters … 267

Turning the Tables … 268

Business on the Live Web … 269

Creating Personal RFQs … 269

Anonymous eCommerce: Building a Real … 272

Fourth-Party Offer Application

The Scenario … 273

Behind the Scenes … 274

The Gory Details … 277

The Scratch Space Module … 278

The Merchant Rule Set … 279

The Offer Rule Set … 281

A Working Fourth-Party eCommerce System … 285

Endnotes … 285

Chapter 14 Designing Event Systems … 287

Life Events as Interaction Scripts … 287

Introducing Scott Phillips … 288

Personal Events … 289

Personal Data … 290

Principles for Personal Event Networks … 291

The Timeline … 293

Understanding the Components … 295

Live Web Desktop … 295

Endpoints … 298

Using Data … 300

The Rule Sets … 301

Events … 303

Processing Email … 304

Choose a Doctor … 304

Set Up an Appointment … 305

Send Health Data … 306

Understanding the Neck-Pain Scenario … 306

Limitations of the Neck-Pain Scenario … 308

Loosely Coupled Rule Sets … 308

Endnotes … 309

Chapter 15 Building the Live Web … 311

Why the Live Web? … 312

Why Now? … 313

Why KRL and KRE? … 313

Conclusion … 314

Endnotes … 315

Appendix A Lexicon … 317

Appendix B Resources … 321

Appendix C Getting Started with KRL … 325

Appendix D Event Semantics … 329

Appendix E The KRL Expression Language … 339

Appendix F The Evented API Specification … 363

Index … 373