in reply to Can someone please write a *working* JSON module
One more thing: talexb suggested to get your JSON from somewhere out there as far as i understood.
This idea seems to be fairly elegant. As you don't need to throw away your Apache/mod_perl stuff etc.
What about this little sketch?
# app.psgi use strict; use warnings; use Plack::Request; use Plack::App::URLMap; use JSON::Tiny qw(encode_json); my $slash = sub { my $env = shift; my $json = encode_json {nose => 'cuke'}; my $status = 200; my $request = Plack::Request->new($env); my $headers = [ 'Content-Type' => 'application/json', 'Content-Length' => length $json, ]; my $body = [ $json ]; [ $status, $headers, $body ]; }; my $urlmap = Plack::App::URLMap->new; $urlmap->mount( "/" => $slash ); my $app = $urlmap->to_app; __END__
Then: starman --listen /tmp/starman.sock.
And then try: echo -e "GET / HTTP/1.0\r\n" | nc -U /tmp/starman.sock.
This should yield:
HTTP/1.0 200 OK Content-Type: application/json Content-Length: 15 Date: Tue, 26 Oct 2021 14:25:29 GMT Connection: close {"nose":"cuke"}
See also Plack::Request and Plack::App::URLMap.
The other links you have already.
Probably Try::Tiny might be helpful for handling malformed JSON.
Regards, Karl
«The Crux of the Biscuit is the Apostrophe»
|
|---|