remote execute program
Ali Çehreli
acehreli at yahoo.com
Fri Mar 23 20:15:01 UTC 2018
On 03/23/2018 12:25 PM, Cecil Ward wrote:
> On Friday, 23 March 2018 at 01:23:56 UTC, Cecil Ward wrote:
>> I am wanting to write a short program (on a ‘server’ you could say)
>> that takes a command, runs it (as on the command line, so an
>> executable with arguments or a shell command) and returns a 3-tuple
>> with an int for the return code, plus the textual outputs that it
>> generates to stdout and stderr.
A popular way of doing it is using a REST API. Your http server should
direct certain URLs to your service and your service should return the
results back. The messages are typically passed as JSON objects.
Another method is using grpc but D is not among the official languages
at their site.
>> The
>> impressive framework that is vibe.d has already been mentioned, but
>> the amount of reading matter is rather daunting.
If you don't want to use vibe.d I'm sure Adam D. Ruppe's arsd repo has
useful modules for you:
https://github.com/adamdruppe
Regarding vibe.d, I hope others can show you simple examples but a REST
service was trivial when I played with vibe.d a few years ago. Look at
"Example of a simple HTTP server" at their site:
import vibe.vibe;
void main()
{
listenHTTP(":8080", &handleRequest);
runApplication();
}
void handleRequest(HTTPServerRequest req, HTTPServerResponse res)
{
if (req.path == "/")
res.writeBody("Hello, World!");
}
Just implement handleRequest and you're done. But it can be better if
your service is RESTful. You can find tutorials here:
http://vibed.org/tutorials
A fortunate problem is that vibe.d has been easier to use since it
started allowing main() written by you. (In the past, it had main()
calling your function.)
Ali
More information about the Digitalmars-d-learn
mailing list