O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

D Web Development

Book Description

Leverage the power of D and the vibe.d framework to develop web applications that are incredibly fast

About This Book

  • Utilize the elegant vibe.d framework to build web applications easily and REST backends with the D programming language
  • Learn about all components of vibe.d to enhance your web development with D
  • A hands-on guide to the vibe.d framework; from static web pages to template-based, interactive and localized web applications with database access and REST backends

Who This Book Is For

Whether you are new to the world of D, or already have developed applications in D, or if you want to leverage the power of D for web development, then this book is ideal for you. Basic knowledge of core web technologies like HTML 5 is helpful but not required. This book explains the difficult details to speed your web development.

What You Will Learn

  • Create amazingly fast web applications with D
  • Use Diet templates to easily create a web user interface
  • Utilize the web framework for interactive applications with input validation and internationalization
  • Access a database to provide persistent storage for your application
  • Extend your application with a REST interface and access other applications via REST
  • Understand vibe.d’s fiber-based approach to asynchronous I/O and use it for integration of existing components
  • Create GUI applications with vibe.d

In Detail

D is a programming language with C-like syntax and static typing. The vibe.d framework builds on powerful D concepts like template meta-programming and compile-time function execution to provide an easy-to-use environment for web applications. The combination of a feature-rich web programming framework with a language compiling to native code solves two common issues in web development today: it accelerates your development and it results in fast, native web applications. Learning the vibe.d framework before you start your application will help you to choose the right features to reach your goal.

This book guides you through all aspects of web development with D and the vibe.d framework.

Covering the popular operating systems today, this guide starts with the setup of your development system. From the first Hello World-style application you will move on to building static web pages with templates. The concise treatment of web forms will give you all the details about form handling and web security. Using the abstractions of the web framework you will learn how to easily validate user input. Next, you will add database access to your application, providing persistent storage for your data. Building on this foundation, you will expose your component and integrate other components via REST. Learning about the internals of vibe.d you will be able to use low-level techniques such as raw TCP access. The vibe.d concepts can also be used for GUI clients, which is the next topic that you will learn. vibe.d is supported by an active community, which adds new functionality. This comprehensive guide concludes with an overview of the most useful vibe.d extensions and where to find them. It also shows you how to integrate these extensions in your application.

The concepts are always illustrated with source code, giving you an insight into how to apply them in your application.

Style and approach

A tutorial-style guide to develop web applications with D and the vibe.d framework. Each topic is explained in detail and illustrated with source code, providing you with hands-on assistance for your application.

Downloading the example code for this book. You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the code file.

Table of Contents

  1. D Web Development
    1. Table of Contents
    2. D Web Development
    3. Credits
    4. Foreword
    5. About the Author
    6. About the Reviewers
    7. www.PacktPub.com
      1. Support files, eBooks, discount offers, and more
        1. Why subscribe?
        2. Free access for Packt account holders
    8. Preface
      1. What this book covers
      2. What you need for this book
      3. Who this book is for
      4. Conventions
      5. Reader feedback
      6. Customer support
        1. Downloading the example code
        2. Downloading the color images of this book
        3. Errata
        4. Piracy
        5. Questions
    9. 1. Getting Started with Your First Web Application
      1. Installing the D compiler and the DUB package manager
        1. Ubuntu and Debian
        2. Fedora
        3. OS X
        4. Windows
        5. Building from source
        6. Verifying your environment
      2. Creating your first web application
        1. Using DUB to set up the project structure
        2. Creating your first template
      3. Summary
    10. 2. Using Templates for Your Web Pages
      1. Benefits of using templates
      2. Creating your first template
        1. Turning the HTML page into a Diet template
        2. Adding inheritance
        3. Using includes
        4. Integrating other languages with blocks and filters
      3. Solving common tasks
        1. Configuring the document type
        2. Comments in a template
        3. More about tags
        4. Localizing your website
        5. Adding D code to your template
      4. Summary
    11. 3. Get Interactive – Forms and Flow Control
      1. Introducing the note application
      2. Creating a template with a simple form
      3. A closer look at route matching
      4. Serving static files
      5. Storing session data
      6. Authenticating the user
        1. Using basic authentication
        2. Using digest authentication
        3. Form-based authentication
          1. Enabling TLS/SSL with your application
      7. Displaying an error page
      8. Uploading files
      9. Summary
    12. 4. Easy Forms with the Web Framework
      1. Taking advantage of unique D features
      2. Converting the note application
        1. Naming the handler functions
        2. Passing values of form fields
        3. Creating sessions and session variables
        4. Putting everything together
      3. Validating user input
        1. Displaying error messages with @errorDisplay
        2. Refining the validation
      4. Adding authentication
      5. Localizing the web content
      6. Summary
    13. 5. Accessing a Database
      1. Choosing the right database technology
        1. Relational databases
        2. A key-value store
        3. Document databases
        4. Making a choice
      2. Using the Redis key-value store
        1. Installing Redis
        2. Accessing Redis from the note application
      3. Using the MongoDB document database
        1. Installing MongoDB
        2. Persisting data with MongoDB
      4. Using the MySQL relational database
        1. Installing MySQL
        2. Using MySQL with vibe.d
      5. Summary
    14. 6. Using the REST Interface
      1. Defining the principles of the World Wide Web
      2. Serializing D to JSON and back
      3. Creating and using a REST service
        1. Providing a service
        2. Using a service
      4. Tailoring the generated REST API
        1. Changing the generated path
        2. Passing parameters
      5. Accessing CouchDB
        1. Installing CouchDB
        2. Testing the REST interface
        3. Implementing the NoteStore service
      6. Summary
    15. 7. The vibe.d Internals
      1. The programming model of vibe.d
        1. What is a fiber?
        2. Benefits of asynchronous I/O
        3. Combining threads, fibers, and asynchronous I/O
      2. Coding your own main function
      3. Performing background work
        1. Running a fiber-based task
        2. Using a thread
      4. Porting an existing driver
      5. An alternative solution for the existing drivers
      6. Summary
    16. 8. Using vibe.d with a GUI Client
      1. The GUI event loop and vibe.d
      2. Creating a Win32 GUI application
      3. Creating an X11 GUI application
      4. Integrating with other GUI toolkits
      5. Summary
    17. 9. Power Your Application with vibe.d Extensions
      1. Publishing your project in the DUB registry
      2. Useful community projects
        1. Adding WebDAV services
        2. Running your own blog
        3. Chatting with IRC
        4. Coding for the Internet of Things
        5. Serving news
        6. Accessing the Apache Cassandra database
      3. Summary
    18. Index