Building Web Applications with Erlang

Book description

Why choose Erlang for web applications? Discover the answer hands-on by building a simple web service with this book. If you’re an experienced web developer who knows basic Erlang, you’ll learn how to work with REST, dynamic content, web sockets, and concurrency through several examples. In the process, you’ll see first-hand that Erlang is ideal for building business-critical services.

Erlang was designed for fault-tolerant, non-stop telecom systems, and building applications with it requires a large set of skills. By the end of the book, you’ll have the information you need to build a basic web service and get it running.

  • Explore the power of Erlang and REST for building web services
  • Serve static and dynamic content with the Yaws web server
  • Use different methods for outputting data to user, such as encoding Erlang data structures into JSON or XML
  • Build an application to listen for HTTP requests, process them, store data, and return useful data
  • Go beyond the request-response model—push data to clients with web sockets
  • Use Erlang and Yaws to stream data from the server to a client

"A book which is truly needed and will help get Erlang to the next level."

—Francesco Cesarini, CEO of Erlang Solutions, author of Erlang Programming.

Table of contents

  1. Building Web Applications with Erlang
  2. SPECIAL OFFER: Upgrade this ebook with O’Reilly
  3. Preface
    1. Who This Book Is For
    2. Learning Erlang
    3. Before You Start
    4. What You Will Learn
    5. The Limits of This Book
    6. Help! It Doesn’t Compile or Run!
      1. Diagnosing the Error
      2. What Version of Erlang and Yaws Are You Running?
      3. Is Everything Loaded Correctly?
      4. Are You Calling Everything Correctly?
      5. Is Mnesia Running with Correct Tables?
      6. Is the Example Just Plain Wrong?
    7. Conventions Used in This Book
    8. Using Code Examples
    9. Safari® Books Online
    10. How to Contact Us
    11. Acknowledgments
  4. 1. Building Scalable Systems with Erlang and REST
    1. Why Erlang?
      1. Erlang’s Advantages
      2. Lack of Types
      3. OTP—For More Than Just Telecom!
    2. Why Web Services? Why REST?
    3. New Opportunities for Scaling and Resilience
      1. Cloud Computing
      2. System Architecture and Erlang Scaling
        1. Scaling up versus scaling out
        2. Amdahl’s law
      3. Data Storage Options
        1. Mnesia
        2. CouchDB
        3. MongoDB
        4. Redis
        5. Riak
  5. 2. Getting Started with Yaws
    1. Working with Yaws
      1. Starting Yaws
      2. Serving Static Files
      3. Compiling, Loading, and Running Code
      4. Clustering Yaws
    2. Dynamic Content in Yaws
      1. EHTML
      2. Headers and Redirects
    3. Templates
      1. ErlyDTL
    4. Logging
      1. Erlang OTP error_logger
  6. 3. Appmods: Dynamic Content in Yaws
    1. Appmod Configuration
    2. When the URI Does Not Correspond to a File
    3. Cookies
    4. Session Handling
    5. Access Control
    6. Interacting with Erlang Services and Business Logic Layers
  7. 4. Implementing REST
    1. Decoding a Request
      1. Extracting the User’s Request
    2. Response and Headers
    3. Building the Response
      1. JSON
      2. XML
    4. Responding to the REST Request
    5. A Full Example
  8. 5. File Upload
    1. The File Upload Request
    2. Saving to Disk
    3. Putting It All Together
    4. Storage in a Distributed System
    5. Saving to Amazon S3
  9. 6. WebSockets
    1. The WebSocket Request
    2. Basic WebSocket Handler
    3. Advanced WebSocket Handler
  10. 7. Streaming
    1. Simple Streaming
  11. 8. Using the HTTP Client
    1. Making a Request
    2. Using OAuth
      1. Facebook Canvas
  12. 9. Building an Application with OTP
    1. Directory Structure
    2. Building an Application Server
    3. The Generic Server
    4. The Multicast Server
    5. Interfacing the Server with the Web
    6. Some Client-Side Code
    7. Let’s Have Some Adult Supervision Around Here!
    8. A Little Optimization
    9. Bundling as an Application
    10. The App File
    11. Wrapping Up OTP
  13. A. Installing Erlang and Yaws
  14. B. Beyond Yaws
    1. Web Servers
      1. Cowboy
      2. MochiWeb
      3. Misultin
    2. Web Frameworks
      1. Chicago Boss
      2. Nitrogen
      3. Zotonic
  15. C. Interfacing with Ruby and Python
    1. Ruby
    2. Python
  16. D. Using Erlang with Emacs
    1. Distel
    2. Flymake Mode
    3. Gen Server Template
  17. About the Author
  18. SPECIAL OFFER: Upgrade this ebook with O’Reilly
  19. Copyright

Product information

  • Title: Building Web Applications with Erlang
  • Author(s): Zachary Kessin
  • Release date: June 2012
  • Publisher(s): O'Reilly Media, Inc.
  • ISBN: 9781449320652