Creating a web API with web.d
My web.d
file is an add-on module for cgi.d
that utilizes D's reflection and code generation capabilities to automate tasks such as URL routing and JSON and HTML generation from your code.
Getting ready
The web.d
file has several dependencies that can be found in my Github repository. You'll need to download each of the files and compile them all together. Download cgi.d
, web.d
, sha.d
, dom.d
, and characterencodings.d
to your project's directory.
How to do it…
Let's execute the following steps to create a web API:
Import
arsd.web
.Create a class that inherits from
ApiProvider
.Write the
export
methods, which implement various functions that you want to expose.Mix in a
main
function from the library withmixin FancyMain!Your_Class_name;
.Compile the program and all dependencies together using any version modifiers you want from
cgi.d
orweb.d
. We can compile with the following command to use the embedded HTTP server and disable the automatic creation of session files...