Last active
December 19, 2018 03:09
-
-
Save leotada/45e4cd6bb00504c9843f446532ab376a to your computer and use it in GitHub Desktop.
Vibe.D Receive JSON Field
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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