Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Can someone please write a *working* JSON module

by karlgoethebier (Abbot)
on Oct 26, 2021 at 14:56 UTC ( [id://11138070]=note: print w/replies, xml ) Need Help??


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»

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11138070]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (3)
As of 2024-04-18 01:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found