Testing the whole thing

Let’s look at source\app.d again:

import vibe.vibe;
import empcontrol;
void main()
{
  auto settings = new HTTPServerSettings;
  settings.port = 8080;
  settings.bindAddresses = ["::1", "127.0.0.1"];
  auto router = new URLRouter;
  router.get("*", serveStaticFiles("public/"));
  router.registerWebInterface(new EmployeeController);
  auto listener = listenHTTP(settings, router);
  scope (exit) listener.stopListening();
 
  runApplication();
}

Then try to compile. If you get errors (the views\empadd.dt is a big file), they may be just simple typographical errors, like this:

500 - Internal Server Error
Internal Server Error
Internal error information:
object.Exception@C:\Users\owner\AppData\Local\dub\packages\vibe-d-0.9.3\vibe-d\data\vibe\data\serialization.d(918): Missing non-optional field 'id' of type 'Employee' (DefaultPolicy(T)).
----------------
0x00007FF611495B23 in std.exception.bailOut!(object.Exception).bailOut at C:\D\dmd2\windows\bin\..\..\src\phobos\std\exception.d(516)
0x00007FF611495A29 in std.exception.enforce!().enforce!bool.enforce at C:\D\dmd2\windows\bin\..\..\src\phobos\std\exception.d(437)
0x00007FF6114FF20A in vibe.data.serialization.deserializeValueImpl!(vibe.data.bson.BsonSerializer, DefaultPolicy).deserializeValueDeduced!(empmongo.Employee).deserializeValueDeduced at C:\D\dmd2\windows\bin\..\..\src\phobos\std\exception.d(434)
0x00007FF6114FF0FD in vibe.data.serialization.deserializeValueImpl!(vibe.data.bson.BsonSerializer, DefaultPolicy).deserializeValue!(empmongo.Employee).deserializeValue at C:\Users\rey\AppData\Local\dub\packages\vibe-d-0.9.3\vibe-d\data\vibe\data\serialization.d(691)
0x00007FF6114FF0B5 in vibe.data.serialization.deserializeWithPolicy!(vibe.data.bson.BsonSerializer, DefaultPolicy, empmongo.Employee, vibe.data.bson.Bson).deserializeWithPolicy at C:\Users\rey\AppData\Local\dub\packages\vibe-d-0.9.3\vibe-d\data\vibe\data\serialization.d(304)
0x00007FF6114FF031 in vibe.data.serialization.deserialize!(vibe.data.bson.BsonSerializer, empmongo.Employee, vibe.data.bson.Bson).deserialize at C:\Users\rey\AppData\Local\dub\packages\vibe-d-0.9.3\vibe-d\data\vibe\data\serialization.d(270)
0x00007FF6114FEFE1 in vibe.data.bson.deserializeBson!(empmongo.Employee).deserializeBson at C:\Users\rey\AppData\Local\dub\packages\vibe-d-0.9.3\vibe-d\data\vibe\data\bson.d(1217)
0x00007FF61150ADB2 in empmongo.EmployeeModel.getEmployees at C:\vibeprojects\lorem\source\empmongo.d(80)
0x00007FF611507728 in loremservice.LoremInterface.getListEmployees at C:\vibeprojects\lorem\source\loremservice.d(166)
0x00007FF6114D7FFF in vibe.web.web.handleRequest!("getListEmployees", getListEmployees, loremservice.LoremInterface).handleRequest at C:\Users\rey\AppData\Local\dub\packages\vibe-d-0.9.3\vibe-d\web\vibe\web\web.d(1043)
0x00007FF61149FFDD in vibe.web.web.registerWebInterface!(loremservice.LoremInterface, MethodStyle.lowerUnderscored).registerWebInterface.__lambda20 at C:\Users\rey\AppData\Local\dub\packages\vibe-d-0.9.3\vibe-d\web\vibe\web\web.d(214)
0x00007FF6115CB2F4 in vibe.http.router.URLRouter.handleRequest.__lambda4 at C:\Users\rey\AppData\Local\dub\packages\vibe-d-0.9.3\vibe-d\http\vibe\http\router.d(218)
0x00007FF6115E294B in vibe.http.router.MatchTree!(vibe.http.router.Route).MatchTree.doMatch at C:\Users\rey\AppData\Local\dub\packages\vibe-d-0.9.3\vibe-d\http\vibe\http\router.d(674)
0x00007FF6115E1C46 in vibe.http.router.MatchTree!(vibe.http.router.Route).MatchTree.match at C:\Users\rey\AppData\Local\dub\packages\vibe-d-0.9.3\vibe-d\http\vibe\http\router.d(607)
0x00007FF6115CAC5D in vibe.http.router.URLRouter.handleRequest at C:\Users\rey\AppData\Local\dub\packages\vibe-d-0.9.3\vibe-d\http\vibe\http\router.d(211)
0x00007FF61164B50A in vibe.http.server.handleRequest at C:\Users\rey\AppData\Local\dub\packages\vibe-d-0.9.3\vibe-d\http\vibe\http\server.d(2292)
0x00007FF61160CD25 in vibe.http.server.handleHTTPConnection.__lambda4 at C:\Users\rey\AppData\Local\dub\packages\vibe-d-0.9.3\vibe-d\http\vibe\http\server.d(253)
0x00007FF61160C587 in vibe.http.server.handleHTTPConnection at C:\Users\rey\AppData\Local\dub\packages\vibe-d-0.9.3\vibe-d\http\vibe\http\server.d(254)
0x00007FF6115E0279 in vibe.http.server.listenHTTPPlain.doListen.__lambda6 at C:\Users\rey\AppData\Local\dub\packages\vibe-d-0.9.3\vibe-d\http\vibe\http\server.d(2048)
0x00007FF61188D255 in void vibe.core.task.TaskFuncInfo.set!(void delegate(vibe.core.net.TCPConnection) @safe, vibe.core.net.TCPConnection).set(ref void delegate(vibe.core.net.TCPConnection) @safe, ref vibe.core.net.TCPConnection).callDelegate(ref vibe.core.task.TaskFuncInfo) at C:\Users\rey\AppData\Local\dub\packages\vibe-core-1.13.0\vibe-core\source\vibe\core\task.d-mixin-712(712)
0x00007FF611856596 in vibe.core.task.TaskFuncInfo.call at C:\Users\rey\AppData\Local\dub\packages\vibe-core-1.13.0\vibe-core\source\vibe\core\task.d(730)
0x00007FF611836AE6 in vibe.core.task.TaskFiber.run at C:\Users\rey\AppData\Local\dub\packages\vibe-core-1.13.0\vibe-core\source\vibe\core\task.d(439)
0x00007FF6119B64CF in void core.thread.context.Callable.opCall()
0x00007FF6119B8BA7 in fiber_entryPoint
0x00007FF61198C989 in pure nothrow @nogc void core.thread.fiber.Fiber.initStack().trampoline()

It is a very long error message but the culprit is just a typo in views\empadd.dt, which is e__id (double underscore) instead of e_id.

Once you resolved the errors, compile, run and refresh your browser.

Then click on Add employee and enter sample data to test the new data-entry system.

And click Submit, which will return this error:

404 - Not Found
Not Found
Internal error information:
No routes match path '/all_employees'

In the class EmployeeController, we have this line at the end of postAddEmployee() method:

redirect("all_employees");

which will become the URL http://localhost:8080/all_employees which corresponds to the method getAllEmployees(), which we haven’t written yet, so let’s write that next.

Last updated