Discussion:
Render http status code + json ?
(too old to reply)
Luc Larochelle
2018-08-28 02:39:45 UTC
Permalink
Hi, what's the proper way to render a status code and a json message at the same time ?

I use Mojolicious Lite.

Best,
Luc
--
You received this message because you are subscribed to the Google Groups "Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.
Stefan Adams
2018-08-28 02:47:42 UTC
Permalink
Post by Luc Larochelle
Hi, what's the proper way to render a status code and a json message at the same time ?
*$ perl -Mojo -E 'a("/" => {status => 404, json => {error => "not
found"}})->start' get -v /*
GET / HTTP/1.1
User-Agent: Mojolicious (Perl)
Content-Length: 0
Host: 127.0.0.1:41463
Accept-Encoding: gzip

*HTTP/1.1 404 Not Found*
Server: Mojolicious (Perl)
Content-Type: application/json;charset=UTF-8
Content-Length: 21
Date: Tue, 28 Aug 2018 02:46:28 GMT

*{"error":"not found"}*
--
You received this message because you are subscribed to the Google Groups "Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.
Luc Larochelle
2018-08-28 13:29:03 UTC
Permalink
well that's interesting for sure , but actually I'm using Mojolicious::Lite
--
You received this message because you are subscribed to the Google Groups "Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.
Luc Larochelle
2018-08-28 13:46:59 UTC
Permalink
What I mean is, how can I pass both types to the renderer ?

$c->render(status => 404, json => {message => 'error'});

Is that the proper way ?
Post by Luc Larochelle
well that's interesting for sure , but actually I'm using Mojolicious::Lite
--
You received this message because you are subscribed to the Google Groups "Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.
Stefan Adams
2018-08-28 13:51:42 UTC
Permalink
Post by Luc Larochelle
What I mean is, how can I pass both types to the renderer ?
$c->render(status => 404, json => {message => 'error'});
Is that the proper way ?
Yep! And FWIW, "Every ojo one-liner is also a Mojolicious::Lite
application. <https://mojolicious.org/perldoc/ojo#toc>" Therefore,
technically, the solution I presented meets your requirements. :) I just
put the Mojolicious::Lite app into a ojo one liner for brevity in showing
code and output!
--
You received this message because you are subscribed to the Google Groups "Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.
Luc Larochelle
2018-08-28 14:45:00 UTC
Permalink
thank u so much for the confirmation. Btw I tried to replicate as per your example in the meanwhile and it works perfectly for me.

Best,
Luc
--
You received this message because you are subscribed to the Google Groups "Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.
Continue reading on narkive:
Loading...