Skip to content

Instantly share code, notes, and snippets.

@yonax
Created June 11, 2018 11:46
Show Gist options
  • Save yonax/a35a095e279e47d3289f74d89c670d14 to your computer and use it in GitHub Desktop.
Save yonax/a35a095e279e47d3289f74d89c670d14 to your computer and use it in GitHub Desktop.
import vibe.vibe;
class SimpleService {
@path("/sendSms") void SendSms(string phone, string text) {
logInfo("Sending sms to [%s] with text [%s]", phone, text);
requestHTTP("http://api.prostor-sms.ru/messages/v2/send.json",
(scope req) {
req.method = HTTPMethod.POST;
req.writeJsonBody([
"name": "My Name",
"login": "login",
"password": "password",
"text": text,
"phone": phone
]);
},
(scope res) {
logInfo("Response: %s", res.bodyReader.readAllUTF8());
}
);
}
}
void main()
{
auto router = new URLRouter;
router.registerWebInterface(new SimpleService);
auto settings = new HTTPServerSettings;
settings.port = 8080;
settings.bindAddresses = ["::1", "127.0.0.1"];
listenHTTP(settings, router);
logInfo("Please open http://127.0.0.1:8080/ in your browser.");
runApplication();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment