Book Image

D Web Development

By : Kai Nacke
Book Image

D Web Development

By: Kai Nacke

Overview of this book

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.
Table of Contents (17 chapters)
D Web Development
About the Author
About the Reviewers


In the cloud age, web technologies are more important than ever. The vibe.d framework enables you to use the D programming language for a wide range of web-related tasks. The D programming language allows elegant solutions for common problems, while native compilation produces fast binaries. The vibe.d framework takes advantage of these language features. Together with the innovative use of fibers, the applications that you build are scalable and have a very quick response time.

This book will explain everything you need to know about the vibe.d framework in order to successfully build and run web applications.

What this book covers

Chapter 1, Getting Started with Your First Web Application, explains how to set up and use your development environment. At the end of this chapter, you will have already created your first web application.

Chapter 2, Using Templates for Your Web Pages, covers the Diet template engine. You will learn all about templates—from creating simple static templates to using D code in templates.

Chapter 3, Get Interactive – Forms and Flow Control, brings web forms to your application and introduces route matching.

Chapter 4, Easy Forms with the Web Framework, discusses how to validate user input.

Chapter 5, Accessing a Database, shows how to use a database in an application using a variety of SQL and NoSQL bases.

Chapter 6, Using the REST Interface, teaches you about REST services. You will learn how to provide and consume a generated REST service. You will also study how to interface with an existing REST service.

Chapter 7, The vibe.d Internals, introduces you to the fiber-based pseudo-blocking programming model that is the base for vibe.d.

Chapter 8, Using vibe.d with a GUI Client, applies the vibe.d programming model to a graphical UI application.

Chapter 9, Power Your Application with vibe.d Extensions, shows you what other developers have already implemented with vibe.d and how to publish your application.

What you need for this book

You need a Linux, Windows, or Mac PC that is capable of running the DMD D compiler and the DUB package manager. Both software packages are available at The vibe.d framework requires an SSL library and the libevent library to be installed. The various sources are described in Chapter 1, Getting Started with Your First Web Application.

In order to compile the examples, you need an Internet connection in order to allow the automatic download of dependent software.

For the example in Chapter 5, Accessing a Database, you need Redis 3.x (available at, MongoDB 3.x (available at, and MySQL 5.x (available at Chapter 6, Using the REST Interface, uses CouchDB (available at and Chapter 9, Power Your Application with vibe.d Extensions, uses Cassandra (available at

Who this book is for

Whether you are new to the world of D, already have developed applications in D, or you want to leverage the power of D for web development, then this book is ideal for you. Basic knowledge of core web technologies, such as HTML 5, is helpful; however, it not necessary. This book explains the complex details to speed your web development.


In this book, you will find a number of text styles that distinguish between different kinds of information. Here are some examples of these styles and an explanation of their meaning.

Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "You also need to install openssl and libevent, which are used by vibe.d."

A block of code is set as follows:

name "hello"
description "A simple vibe.d server application."
copyright "Copyright © 2015, <yourid>"
authors "<yourid>"
dependency "vibe-d" version="~>0.7.23"
versions "VibeDefaultMain"

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

  block header
    header Header
  block navigation
    include navigation
  block content
  block footer
    footer Footer

Any command-line input or output is written as follows:

$ tar xvzf dub-0.9.24.tar.gz
$ cd dub-0.9.24
$ ./

New terms and important words are shown in bold. Words that you see on the screen, for example, in menus or dialog boxes, appear in the text like this: "Click on the Unlock button to unlock the window and change the account type to Administrator."


Warnings or important notes appear in a box like this.


Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of.

To send us general feedback, simply e-mail , and mention the book's title in the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide at

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files from your account at for all the Packt Publishing books you have purchased. If you purchased this book elsewhere, you can visit and register to have the files e-mailed directly to you.

Downloading the color images of this book

We also provide you with a PDF file that has color images of the screenshots/diagrams used in this book. The color images will help you better understand the changes in the output. You can download this file from


Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you could report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting, selecting your book, clicking on the Errata Submission Form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website or added to any list of existing errata under the Errata section of that title.

To view the previously submitted errata, go to and enter the name of the book in the search field. The required information will appear under the Errata section.


Piracy of copyrighted material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at with a link to the suspected pirated material.

We appreciate your help in protecting our authors and our ability to bring you valuable content.


If you have a problem with any aspect of this book, you can contact us at , and we will do our best to address the problem.