Discover millions of ebooks, audiobooks, and so much more with a free trial

Only $11.99/month after trial. Cancel anytime.

D Web Development
D Web Development
D Web Development
Ebook380 pages2 hours

D Web Development

Rating: 0 out of 5 stars

()

Read preview

About this ebook

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.

LanguageEnglish
Release dateJan 30, 2016
ISBN9781785280108
D Web Development

Read more from Nacke Kai

Related to D Web Development

Related ebooks

Internet & Web For You

View More

Related articles

Reviews for D Web Development

Rating: 0 out of 5 stars
0 ratings

0 ratings0 reviews

What did you think?

Tap to rate

Review must be at least 10 words

    Book preview

    D Web Development - Nacke Kai

    (missing alt)

    Table of Contents

    D Web Development

    Credits

    Foreword

    About the Author

    About the Reviewers

    www.PacktPub.com

    Support files, eBooks, discount offers, and more

    Why subscribe?

    Free access for Packt account holders

    Preface

    What this book covers

    What you need for this book

    Who this book is for

    Conventions

    Reader feedback

    Customer support

    Downloading the example code

    Downloading the color images of this book

    Errata

    Piracy

    Questions

    1. Getting Started with Your First Web Application

    Installing the D compiler and the DUB package manager

    Ubuntu and Debian

    Fedora

    OS X

    Windows

    Building from source

    Verifying your environment

    Creating your first web application

    Using DUB to set up the project structure

    Creating your first template

    Summary

    2. Using Templates for Your Web Pages

    Benefits of using templates

    Creating your first template

    Turning the HTML page into a Diet template

    Adding inheritance

    Using includes

    Integrating other languages with blocks and filters

    Solving common tasks

    Configuring the document type

    Comments in a template

    More about tags

    Localizing your website

    Adding D code to your template

    Summary

    3. Get Interactive – Forms and Flow Control

    Introducing the note application

    Creating a template with a simple form

    A closer look at route matching

    Serving static files

    Storing session data

    Authenticating the user

    Using basic authentication

    Using digest authentication

    Form-based authentication

    Enabling TLS/SSL with your application

    Displaying an error page

    Uploading files

    Summary

    4. Easy Forms with the Web Framework

    Taking advantage of unique D features

    Converting the note application

    Naming the handler functions

    Passing values of form fields

    Creating sessions and session variables

    Putting everything together

    Validating user input

    Displaying error messages with @errorDisplay

    Refining the validation

    Adding authentication

    Localizing the web content

    Summary

    5. Accessing a Database

    Choosing the right database technology

    Relational databases

    A key-value store

    Document databases

    Making a choice

    Using the Redis key-value store

    Installing Redis

    Accessing Redis from the note application

    Using the MongoDB document database

    Installing MongoDB

    Persisting data with MongoDB

    Using the MySQL relational database

    Installing MySQL

    Using MySQL with vibe.d

    Summary

    6. Using the REST Interface

    Defining the principles of the World Wide Web

    Serializing D to JSON and back

    Creating and using a REST service

    Providing a service

    Using a service

    Tailoring the generated REST API

    Changing the generated path

    Passing parameters

    Accessing CouchDB

    Installing CouchDB

    Testing the REST interface

    Implementing the NoteStore service

    Summary

    7. The vibe.d Internals

    The programming model of vibe.d

    What is a fiber?

    Benefits of asynchronous I/O

    Combining threads, fibers, and asynchronous I/O

    Coding your own main function

    Performing background work

    Running a fiber-based task

    Using a thread

    Porting an existing driver

    An alternative solution for the existing drivers

    Summary

    8. Using vibe.d with a GUI Client

    The GUI event loop and vibe.d

    Creating a Win32 GUI application

    Creating an X11 GUI application

    Integrating with other GUI toolkits

    Summary

    9. Power Your Application with vibe.d Extensions

    Publishing your project in the DUB registry

    Useful community projects

    Adding WebDAV services

    Running your own blog

    Chatting with IRC

    Coding for the Internet of Things

    Serving news

    Accessing the Apache Cassandra database

    Summary

    Index

    D Web Development


    D Web Development

    Copyright © 2016 Packt Publishing

    All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.

    Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.

    Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.

    First published: January 2016

    Production reference: 1250116

    Published by Packt Publishing Ltd.

    Livery Place

    35 Livery Street

    Birmingham B3 2PB, UK.

    ISBN 978-1-78528-889-0

    www.packtpub.com

    Credits

    Author

    Kai Nacke

    Reviewers

    Orfeo Da Vià

    Stephan Dilly

    Paul Féraud

    Kazuki Komatsu

    Adam D. Ruppe

    Robert burner Schadek

    Acquisition Editor

    Tushar Gupta

    Content Development Editor

    Merwyn D'souza

    Technical Editor

    Pranil Pathare

    Copy Editor

    Tasneem Fatehi

    Project Coordinator

    Neha Bhatnagar

    Proofreader

    Safis Editing

    Indexer

    Mariammal Chettiyar

    Production Coordinator

    Arvindkumar Gupta

    Cover Work

    Arvindkumar Gupta

    Foreword

    As a general-purpose language, D has held good potential of being applied in the burgeoning web server domain. D's build speed makes its convenience close to that of scripting languages—the argument goes—and there's also a lot to like about the running speed of the resulting native code, too.

    This has remained a theoretical possibility for a good while, until vibe.d came out of nowhere to take the D community by storm. The vibe.d framework is everything that I'd hoped it to be—a comprehensive, compelling, modern framework that wonderfully uses D's features to strike a balance between flexibility, performance, and ease of use.

    It is everything I hoped... except for one thing. It doesn't have a good book teaching it properly. Therefore, it's easy to imagine my giddiness now that I was offered the honor to write this foreword for such a book.

    Written by Kai Nacke, a long-standing and respected luminary of the D community (known among other things for LDC, the LLVM-based D compiler), D Web Development does an admirable job of taking its reader from not knowing much about web development (as I confess your truly is, or at least was) to getting a high-performance server up and running. Also, customizing it in so many ways: content, localization, data connectivity, interoperation, and defining extensions.

    Since its creation, vibe.d has slowly but surely become one of the most important frameworks written in D and simultaneously one of the best examples of using D on large scale, so much so that vibe.d is being made part of the reference D distribution. This book is a necessary and welcome term of that equation.

    Andrei Alexandrescu

    Co-developer of the D programming language

    About the Author

    Kai Nacke is a professional IT architect living in Düsseldorf, Germany. He holds a diploma in computer science from the University of Dortmund. His diploma thesis about universal hash functions was recognized as the best of the semester. He has been with IBM for more than 15 years, and has great experience in the development and architecture of business and enterprise applications.

    Fascinated by the first home computer, he learned to program a VIC-20 in BASIC. Later, he turned to Turbo PASCAL and Small C on CP/M. Experimenting with the source of Small C created his interest in compiler technology. Many computers, operating systems, and languages followed these first steps.

    Around 2005, he became interested in the D programming language and created the first fun applications in D. Missing a 64-bit D compiler for Windows, he started to contribute to the LLVM compiler framework and LDC, the LLVM-based D compiler. Soon, he became committer of both projects and is now the current maintainer of LDC.

    He is also a speaker at the Free and Open Source Software Developers' European Meeting (FOSDEM) and was one of the reviewers of D Cookbook, Packt Publishing.

    Writing a book is challenging. I would like to thank everybody who supported me by answering questions, accepting pull requests, or by simply encouraging me to go on. I would also like to thank the reviewers who did a great job. Their comments really contributed to the quality of the book.

    About the Reviewers

    Orfeo Da Vià is an Italian software developer and has been professionally developing software since 1994. Over the past four years, he has written a number of D software applications.

    Orfeo is currently employed as a senior developer at Microline.

    Outside the software world, Orfeo enjoys spending time with his two daughters, Raffaella and Adele, and his wife, Alessandra.

    Stephan Dilly works as the head of front-end engineering at InnoGames in Germany. In the nine years of professional software development, he has worked in the games industry for Funatics and Ubisoft Blue Byte. He has also worked as a software consultant at Sopra Steria Consulting. The D programming language has been his language of choice for his spare-time projects since 2006. In 2014, Stephan was a speaker at the DConf in San Francisco, where he talked about a backend server architecture developed in D.

    Paul Féraud is software engineer with passion for math, algorithms, and programming. He holds a diplôme d'Ingénieur in mechanical engineering from the École Centrale de Nantes in France and a master's degree in software engineering from Keio University in Japan.

    Paul has worked for Amadeus, developing a business rule engine that is designed for very high throughput. He has also worked for Dassault Systèmes, developing the architecture backing SIMULIA's finite element simulation systems.

    In parallel to this, Paul took great interest in the D programming language and began contributing to its development. He became a member of the core development team and has participated in the design and implementation of its standard library.

    Paul now works for Google in Switzerland. He spends most of his time raising his beautiful daughter with his loving and supporting wife.

    Kazuki Komatsu is a university student, currently majoring in wireless communication engineering. He started learning D programming language at the age of 16. He has been writing D grammar documents in Japanese and creating a variety of D libraries, such as linear algebra, compile-time meta programming, and Twitter client. Recently, Kazuki has been creating GUI toolkit, awebview, which is similar to GitHub's Electron; however, awebview is written with D and we can write GUI apps with D, HTML, CSS, and JavaScript.

    Adam D. Ruppe is the author of D Cookbook, Packt Publishing and a long-time contributor to the D ecosystem.

    Robert burner Schadek is a regular contributor to the standard D library, Phobos. His D journey started when he used D to create a Distributed Multithreaded Caching D compiler for his computer science master's thesis. He presented this work at DConf 2013. His commitment to Phobos can be seen all over the library. His biggest contribution to Phobos is the experimental logging framework. He is currently working on his PhD in computer science at the University of Oldenburg, Germany. There, he uses the high-performance computing (HPC) facility of the university and a lot of C++ to crunch the numbers on his original data-replication protocol. However, during his programming, he has learned one thing to be true—every untested function is buggy.

    www.PacktPub.com

    Support files, eBooks, discount offers, and more

    For support files and downloads related to your book, please visit www.PacktPub.com.

    Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at for more details.

    At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks.

    Support files, eBooks, discount offers, and more

    https://www2.packtpub.com/books/subscription/packtlib

    Do you need instant solutions to your IT questions? PacktLib is Packt's online digital book library. Here, you can search, access, and read Packt's entire library of books.

    Why subscribe?

    Fully searchable across every book published by Packt

    Copy and paste, print, and bookmark content

    On demand and accessible via a web browser

    Free access for Packt account holders

    If you have an account with Packt at www.PacktPub.com, you can use this to access PacktLib today and view 9 entirely free books. Simply use your login credentials for immediate access.

    Preface

    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

    Enjoying the preview?
    Page 1 of 1