Opa: Up and Running

Book description

Want to simplify web development? This hands-on book shows you how to write frontend and backend code simultaneously, using the Opa framework. Opa provides a complete stack for web application development, including a web server, database engine, distribution libraries, and a programming language that compiles to JavaScript.

You’ll learn step-by-step how to use Opa by building two projects through the course of the book: a wiki application similar to Wikipedia, and a Twitter-like micro-blogging platform. Discover how easy it is to use Opa to develop applications with real-time updates, database interactions, and web service design. Do you have JavaScript experience? You’re ready to get started.

  • Learn fundamental concepts, including Opa’s functional programming style
  • Discover how Opa compiles to JavaScript, using jQuery on the frontend and Node.js on the server
  • Construct HTML resources dynamically and embed static resources on an Opa server
  • Use Opa’s method for performing CRUD operations and storing key-value pairs in MongoDB
  • Build an Opa user interface with the Bootstrap toolkit from Twitter
  • Learn variant types, pattern-matching, polymorphic types, recursive functions, and other advanced features
  • Manage user accounts by building login forms, handling account activation, and tracking logged users
  • Build a reactive UI—a real-time interface that continuously updates user events

Publisher resources

View/Submit Errata

Table of contents

  1. Opa: Up and Running
  2. Preface
    1. What Is Opa?
    2. How Do I Work with Opa?
    3. Conventions Used in This Book
    4. Using Code Examples
    5. Safari® Books Online
    6. How to Contact Us
    7. Acknowledgments
  3. I. Coding a Mini Wikipedia
    1. 1. First Steps: Getting to Know Opa
      1. Installing Opa
        1. Installing Node.js
        2. Auto-Installing MongoDB
      2. Our First Program
        1. Writing and Running the Code
        2. What localhost:8080 Means
        3. What the Code Means
        4. What Happens When We Run Your Application
        5. Details About the Opa Runtime
      3. Toward Real Programs
      4. Battle Plan
      5. Summary
    2. 2. Opa Fundamentals
      1. Primitive Values
      2. Dynamic Content
      3. Records
      4. Introduction to Types, and More About Records
      5. A Brief Introduction to Variants
      6. Functions: Building Blocks
      7. Functional Programming
      8. Functional + Typed
      9. Summary
    3. 3. Servers, Resources, and URLs
      1. Web Resources
      2. Embedding (Static) Resources
      3. Serving Resources
      4. Constructing (Dynamic) Resources
      5. URL Dispatching
      6. Summary
    4. 4. Data Storage
      1. CRUD (Create, Read, Update, and Delete)
      2. Maps (Dictionaries)
      3. Summary
    5. 5. Building the UI in HTML and CSS
      1. HTML Markup
        1. Tags and Attributes
        2. Inserts
        3. Event Handlers
        4. DOM Manipulation
        5. Example: A Guessing Game
      2. The Wiki Interface (HTML)
        1. HTML Plumbing
        2. Markdown
        3. Dynamically Updating the Page
      3. Adding Style (CSS)
        1. Explicit Style Attributes
        2. Opa-Powered Style
        3. External CSS
        4. Wiki with Style
      4. Bootstrap: Nice, Out-of-the-Box Styling
      5. Working with Designers
        1. How Should I Use the DOM Structure?
        2. Can You Describe Your Development Environment?
        3. How Should I Write CSS with Opa?
        4. Which Tools Should I Use to Write CSS?
        5. How Do I Improve the CSS Workflow in Opa?
        6. How Often Should Developers and Designers Interact?
        7. What Should Developers Know About CSS?
        8. What Should Designers Know About Opa?
        9. Can You Provide Some Tips for Quickly Customizing Your App’s Bootstrap-Based UI?
      6. Summary
  4. II. Coding a Mini-Twitter
    1. 6. The Web Chat App
      1. Starting a New Project
      2. View: Building User Interface
      3. Model: Application Logic
      4. Connecting the Model and the View
        1. Showing New Messages
        2. Broadcasting the Current User’s Messages
        3. Connecting Everything
      5. Understanding Networks
      6. Exercises
        1. Customizing the Display
        2. Saying “Hello”
        3. Distinguishing Messages Between Users
        4. User Customization
        5. And Beyond
    2. 7. More Advanced Features of Opa
      1. Learning More About Types
        1. Variant Types
        2. Pattern Matching
        3. Polymorphic Types
        4. Recursive Types
      2. Recursive Functions
      3. What About Loops?
      4. Bigger Projects
      5. Packages
      6. Summary
    3. 8. User Management
      1. Setting Up the View
      2. Bootstrap Widgets: Modal Windows
      3. Form Handling in Opa: Registration Form
        1. Alerts
      4. Modeling and Adding Users
      5. Account Creation Notification: Sending Emails
      6. Activating a User Account Without an Activation Email
      7. Account Activation: URL Data Handling
      8. Keeping Track of Logged-In User: Handling User Associated Data
      9. The User’s Top-Bar Menu
      10. Exercise
      11. Summary
    4. 9. Building Reactive UIs: New Messages with a Real-Time Preview
      1. Parsing
        1. Parsing Expressions
      2. Modeling Messages
      3. Rendering Messages
      4. Reactive UI: Live Preview
      5. Summary
    5. 10. Data Storage and Querying: Storing and Fetching Relevant Messages
      1. Collections in Opa: Lists, Sets, and Maps
      2. Declaring Data
      3. Inserting/Updating Data
      4. Reading (and Querying) Data
        1. Projections
      5. Data Manipulations in Birdy
        1. Database Declaration
        2. Storing New Messages
        3. Fetching Relevant Messages
        4. User and Topic Pages
        5. Following Users and Topics
        6. Following Users
        7. Following Topics
        8. Follow Button
      6. Exercise
      7. Summary
  5. About the Authors
  6. Colophon
  7. Copyright

Product information

  • Title: Opa: Up and Running
  • Author(s): Henri Binsztok, Adam Koprowski, Ida Swarczewskaja
  • Release date: February 2013
  • Publisher(s): O'Reilly Media, Inc.
  • ISBN: 9781449328818