Skip to content

Instantly share code, notes, and snippets.

@leotada
Last active December 19, 2018 03:09
Show Gist options
  • Save leotada/45e4cd6bb00504c9843f446532ab376a to your computer and use it in GitHub Desktop.
Save leotada/45e4cd6bb00504c9843f446532ab376a to your computer and use it in GitHub Desktop.
Vibe.D Receive JSON Field
import vibe.vibe;
import vibe.core.log;
import std.conv;
void main()
{
listenHTTP("localhost:8080", &handleRequest);
runApplication();
}
void handleRequest(HTTPServerRequest req, HTTPServerResponse res)
{
if (req.path == "/")
{
auto json = req.json;
logInfo(req.json.toString());
float value = to!float(req.json["value"].get!string);
string response = "calculation: ";
value *= 3;
res.writeBody(response ~ to!string(value));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment