Mailing List Archive

EMBPERL: accepting json
Good to know that there are still some Embperl users out there.

We have a large SAAS system mainly in Embperl, so our usage of Embperl
is not going away anytime soon.


My current question to the Embperl community is:

*How to accept **application/json?*

**I know that "Embperl uses CGI.pm internally to process forms encoded
with multipart/form-data" and that get processed into %fdat.

Is there a way to disable this behavior dynamically per page to accept
application/json data.

Thanks,
~Donavon
Re: EMBPERL: accepting json [ In reply to ]
On 09/02/2016 06:43 PM, Donavon wrote:
> Good to know that there are still some Embperl users out there.
>
> We have a large SAAS system mainly in Embperl, so our usage of Embperl
> is not going away anytime soon.
>
>
> My current question to the Embperl community is:
>
> *How to accept **application/json?*
>

jsom is not compatiable and shouldn't be used anyway

turning of %fdat essentially crippled embperl

> **I know that "Embperl uses CGI.pm internally to process forms encoded
> with multipart/form-data" and that get processed into %fdat.
>
> Is there a way to disable this behavior dynamically per page to accept
> application/json data.
>
> Thanks,
> ~Donavon
>
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org
Re: EMBPERL: accepting json [ In reply to ]
I wouldn't use embperl to accept json. I see embperl as being designed for
HTML output, so I don't really see how it helps when dealing with json.

On Fri, Sep 2, 2016 at 11:43 PM, Donavon <donl@mycopanet.com> wrote:

> Good to know that there are still some Embperl users out there.
>
> We have a large SAAS system mainly in Embperl, so our usage of Embperl is
> not going away anytime soon.
>
>
> My current question to the Embperl community is:
>
> *How to accept **application/json?*
>
> I know that "Embperl uses CGI.pm internally to process forms encoded with
> multipart/form-data" and that get processed into %fdat.
>
> Is there a way to disable this behavior dynamically per page to accept
> application/json data.
>
> Thanks,
> ~Donavon
>
>
>
>
Re: EMBPERL: accepting json [ In reply to ]
I agree with all of the responses that Embed perl was made to mainly use
CGI.pm and multipart/form-data and really shouldn't be used outside of that.

BUT As long as there is possibility that it might be able to receive
application/json data I have to look for a way to do it. It's part of my
job to look for solutions that work within current limitations.

If every response to this email is "It's not possible" that is something
I can take to a meeting. If the responses are "You shouldn't or it's
difficult" then I have to keep searching for a solution that is
understandable and workable.

I'm willing to pay a small consulting fee or a donation to a charity,
for assistance in figuring this out.

So what are the suggestions for handling a call like this on a script by
script basis. I might be possible to limit the scripts accepting these
calls to specific directories.

|varformData
={"data1":a,"data2":b,"data3":c};$.ajax({dataType:"json",contentType
:"application/json; charset=UTF-8",url:'/folder1/doSomething1.epl',data
:formData,success:function(response){CurrentArray=response;}}); Thank
You, ~Donavon |






On 9/4/2016 2:30 AM, Michael Smith wrote:
> I wouldn't use embperl to accept json. I see embperl as being
> designed for HTML output, so I don't really see how it helps when
> dealing with json.
>
> On Fri, Sep 2, 2016 at 11:43 PM, Donavon <donl@mycopanet.com
> <mailto:donl@mycopanet.com>> wrote:
>
> Good to know that there are still some Embperl users out there.
>
> We have a large SAAS system mainly in Embperl, so our usage of
> Embperl is not going away anytime soon.
>
>
> My current question to the Embperl community is:
>
> *How to accept **application/json?*
>
> **I know that "Embperl uses CGI.pm internally to process forms
> encoded with multipart/form-data" and that get processed into %fdat.
>
> Is there a way to disable this behavior dynamically per page to
> accept application/json data.
>
> Thanks,
> ~Donavon
>
>
>
>
Re: EMBPERL: accepting json [ In reply to ]
On 09/08/2016 01:04 PM, Donavon wrote:
> I agree with all of the responses that Embed perl was made to mainly use
> CGI.pm and multipart/form-data and really shouldn't be used outside of that.
>
> BUT As long as there is possibility that it might be able to receive
> application/json data I have to look for a way to do it. It's part of
> my job to look for solutions that work within current limitations.
>
> If every response to this email is "It's not possible" that is something
> I can take to a meeting. If the responses are "You shouldn't or it's
> difficult" then I have to keep searching for a solution that is
> understandable and workable.
>
> I'm willing to pay a small consulting fee or a donation to a charity,
> for assistance in figuring this out.
>
> So what are the suggestions for handling a call like this on a script by
> script basis. I might be possible to limit the scripts accepting these
> calls to specific directories.
>
> |varformData
> ={"data1":a,"data2":b,"data3":c};$.ajax({dataType:"json",contentType
> :"application/json; charset=UTF-8",url:'/folder1/doSomething1.epl',data
> :formData,success:function(response){CurrentArray=response;}}); Thank
> You, ~Donavon |
>
>
>
>
>
>
> On 9/4/2016 2:30 AM, Michael Smith wrote:
>> I wouldn't use embperl to accept json. I see embperl as being
>> designed for HTML output, so I don't really see how it helps when
>> dealing with json.
>>
>> On Fri, Sep 2, 2016 at 11:43 PM, Donavon <donl@mycopanet.com
>> <mailto:donl@mycopanet.com>> wrote:
>>
>> Good to know that there are still some Embperl users out there.
>>
>> We have a large SAAS system mainly in Embperl, so our usage of
>> Embperl is not going away anytime soon.
>>
>>
>> My current question to the Embperl community is:
>>
>> *How to accept **application/json?*
>>
>> **I know that "Embperl uses CGI.pm internally to process forms
>> encoded with multipart/form-data" and that get processed into %fdat.
>>
>> Is there a way to disable this behavior dynamically per page to
>> accept application/json data.
>>
>> Thanks,
>> ~Donavon
>>
>>
>>
>>
>


Your not understanding or I'm not understanding. JSOM is a CLIENT
technology and EMBPERL is a server technology. It can process ANY input
and it doesn't give a darn about application/json.

all the form data is in %fdat, whether you like it or not, and it is
done on the server side. If you don't want to use something from the
hash, don't use it. %fdat in of itself does not produce any html


--
So many immigrant groups have swept through our town
that Brooklyn, like Atlantis, reaches mythological
proportions in the mind of the world - RI Safir 1998
http://www.mrbrklyn.com

DRM is THEFT - We are the STAKEHOLDERS - RI Safir 2002
http://www.nylxs.com - Leadership Development in Free Software
http://www2.mrbrklyn.com/resources - Unpublished Archive
http://www.coinhangout.com - coins!
http://www.brooklyn-living.com

Being so tracked is for FARM ANIMALS and and extermination camps,
but incompatible with living as a free human being. -RI Safir 2013

---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org
Re: EMBPERL: accepting json [ In reply to ]
Donavon wrote:
> I agree with all of the responses that Embed perl was made to mainly use
> CGI.pm and multipart/form-data and really shouldn't be used outside of that.
>
> BUT As long as there is possibility that it might be able to receive
> application/json data I have to look for a way to do it. It's part of my
> job to look for solutions that work within current limitations.
>
> If every response to this email is "It's not possible" that is something
> I can take to a meeting. If the responses are "You shouldn't or it's
> difficult" then I have to keep searching for a solution that is
> understandable and workable.
>
> I'm willing to pay a small consulting fee or a donation to a charity,
> for assistance in figuring this out.
>
> So what are the suggestions for handling a call like this on a script by
> script basis. I might be possible to limit the scripts accepting these
> calls to specific directories.
>
> |varformData
> ={"data1":a,"data2":b,"data3":c};$.ajax({dataType:"json",contentType
> :"application/json; charset=UTF-8",url:'/folder1/doSomething1.epl',data
> :formData,success:function(response){CurrentArray=response;}}); Thank
> You, ~Donavon |
>
>
>
>
>
>
> On 9/4/2016 2:30 AM, Michael Smith wrote:
>> I wouldn't use embperl to accept json. I see embperl as being
>> designed for HTML output, so I don't really see how it helps when
>> dealing with json.
>>
>> On Fri, Sep 2, 2016 at 11:43 PM, Donavon <donl@mycopanet.com
>> <mailto:donl@mycopanet.com>> wrote:
>>
>> Good to know that there are still some Embperl users out there.
>>
>> We have a large SAAS system mainly in Embperl, so our usage of
>> Embperl is not going away anytime soon.
>>
>>
>> My current question to the Embperl community is:
>>
>> *How to accept **application/json?*
>>
>> **I know that "Embperl uses CGI.pm internally to process forms
>> encoded with multipart/form-data" and that get processed into %fdat.
>>
>> Is there a way to disable this behavior dynamically per page to
>> accept application/json data.
>>
>> Thanks,
>> ~Donavon

Perhaps I am misunderstanding the scenario you are dealing with, but I
use json in my regular Embperl-based website all the time to communicate
with the client side Javascript. On the client side I just use
JSON.parse and JSON.stringify to decode/encode objects for sending via
regular POST calls. And on the server side, I get that data through the
usual %fdat and decode it using JSON::Parse. This is all done using the
regular, vanilla Embperl GET/POST. So unless you are dealing with some
other third party application that you have no control over (i.e.
something is generating calls that are specifically application/json), I
don't see why using JSON with Embperl is an issue. After all, JSON is
really just a way of encoding objects as text, like XML.

I also generate application/xml responses using Embperl, just set
$http_headers_out{'Content-type'} to whatever you are using and then
make sure the actual output matches that format. What I do is have a
base.epl that figures out what the current request is about (usually via
a page_type() sub that is redefined in subdirectories using
Embperl::Object), and then base.epl calls e.g. base_html.epl if it's a
regular web page, or base_xml.epl if it's going to be an xml response,
or base_text.epl if it's a simple text response etc.

Sorry, I don't know if I'm completely missing the point, but it's very
easy to work with json in Embperl. Unless, like I said, you have some
other application that is actually generating application/json calls,
and you have no control over that, and you're trying to figure out how
to get Embperl to even handle those requests... if that's the case, then
ok, I'm not sure how that would work with %fdat etc.

Neil


---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org
Re: EMBPERL: accepting json [ In reply to ]
On 09/08/2016 01:21 PM, Neil Gunton wrote:
> I also generate application/xml responses using Embperl,


Embperl can use perl modules to spit out anything that is a string of bits.


--
So many immigrant groups have swept through our town
that Brooklyn, like Atlantis, reaches mythological
proportions in the mind of the world - RI Safir 1998
http://www.mrbrklyn.com

DRM is THEFT - We are the STAKEHOLDERS - RI Safir 2002
http://www.nylxs.com - Leadership Development in Free Software
http://www2.mrbrklyn.com/resources - Unpublished Archive
http://www.coinhangout.com - coins!
http://www.brooklyn-living.com

Being so tracked is for FARM ANIMALS and and extermination camps,
but incompatible with living as a free human being. -RI Safir 2013

---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org
Re: EMBPERL: accepting json [ In reply to ]
If the following call is made:

<script>

|varformData
={"data1":a,"data2":b,"data3":c};$.ajax({dataType:"json",contentType
:"application/json; charset=UTF-8",url:'/folder1/doSomething1.epl',data
:formData,success:function(response){CurrentArray=response;}}); </script> ||doSomething1.epl| doesn't receive the JSON data as %fdat. %fdat is empty.





On 9/8/2016 10:18 AM, Ruben Safir wrote:
> On 09/08/2016 01:04 PM, Donavon wrote:
>> I agree with all of the responses that Embed perl was made to mainly use
>> CGI.pm and multipart/form-data and really shouldn't be used outside of that.
>>
>> BUT As long as there is possibility that it might be able to receive
>> application/json data I have to look for a way to do it. It's part of
>> my job to look for solutions that work within current limitations.
>>
>> If every response to this email is "It's not possible" that is something
>> I can take to a meeting. If the responses are "You shouldn't or it's
>> difficult" then I have to keep searching for a solution that is
>> understandable and workable.
>>
>> I'm willing to pay a small consulting fee or a donation to a charity,
>> for assistance in figuring this out.
>>
>> So what are the suggestions for handling a call like this on a script by
>> script basis. I might be possible to limit the scripts accepting these
>> calls to specific directories.
>>
>> |varformData
>> ={"data1":a,"data2":b,"data3":c};$.ajax({dataType:"json",contentType
>> :"application/json; charset=UTF-8",url:'/folder1/doSomething1.epl',data
>> :formData,success:function(response){CurrentArray=response;}}); Thank
>> You, ~Donavon |
>>
>>
>>
>>
>>
>>
>> On 9/4/2016 2:30 AM, Michael Smith wrote:
>>> I wouldn't use embperl to accept json. I see embperl as being
>>> designed for HTML output, so I don't really see how it helps when
>>> dealing with json.
>>>
>>> On Fri, Sep 2, 2016 at 11:43 PM, Donavon <donl@mycopanet.com
>>> <mailto:donl@mycopanet.com>> wrote:
>>>
>>> Good to know that there are still some Embperl users out there.
>>>
>>> We have a large SAAS system mainly in Embperl, so our usage of
>>> Embperl is not going away anytime soon.
>>>
>>>
>>> My current question to the Embperl community is:
>>>
>>> *How to accept **application/json?*
>>>
>>> **I know that "Embperl uses CGI.pm internally to process forms
>>> encoded with multipart/form-data" and that get processed into %fdat.
>>>
>>> Is there a way to disable this behavior dynamically per page to
>>> accept application/json data.
>>>
>>> Thanks,
>>> ~Donavon
>>>
>>>
>>>
>>>
>
> Your not understanding or I'm not understanding. JSOM is a CLIENT
> technology and EMBPERL is a server technology. It can process ANY input
> and it doesn't give a darn about application/json.
>
> all the form data is in %fdat, whether you like it or not, and it is
> done on the server side. If you don't want to use something from the
> hash, don't use it. %fdat in of itself does not produce any html
>
>
Re: EMBPERL: accepting json [ In reply to ]
Yup. that's it.

If I use Embperl to create JSON data no problem.

I just do:

[-

| use| |JSON;|| $hash{'key'} = 'value||';|||| $json| |=
encode_json(\||%hash||);|

| $http_headers_out||{||'Content-Type'||} =
||"application/json; charset=utf-8"||; |||
|| $escmode| |= 0;||| print| |OUT ||$json||;|

|-] If I use Embperl to receive JSON data. That's where the issue
arises. <script> |

var formData = {"data1":a,"data2":b,"data3":c};

$.ajax(

{dataType:"json",

contentType:"application/json; charset=UTF-8",

url:'/folder1/doSomething1.epl',

data:formData, success:function(response){ CurrentArray=response; } });
</script>



On 9/8/2016 10:21 AM, Neil Gunton wrote:
> Donavon wrote:
>> I agree with all of the responses that Embed perl was made to mainly use
>> CGI.pm and multipart/form-data and really shouldn't be used outside
>> of that.
>>
>> BUT As long as there is possibility that it might be able to receive
>> application/json data I have to look for a way to do it. It's part of my
>> job to look for solutions that work within current limitations.
>>
>> If every response to this email is "It's not possible" that is something
>> I can take to a meeting. If the responses are "You shouldn't or it's
>> difficult" then I have to keep searching for a solution that is
>> understandable and workable.
>>
>> I'm willing to pay a small consulting fee or a donation to a charity,
>> for assistance in figuring this out.
>>
>> So what are the suggestions for handling a call like this on a script by
>> script basis. I might be possible to limit the scripts accepting these
>> calls to specific directories.
>>
>> |varformData
>> ={"data1":a,"data2":b,"data3":c};$.ajax({dataType:"json",contentType
>> :"application/json; charset=UTF-8",url:'/folder1/doSomething1.epl',data
>> :formData,success:function(response){CurrentArray=response;}}); Thank
>> You, ~Donavon |
>>
>>
>>
>>
>>
>>
>> On 9/4/2016 2:30 AM, Michael Smith wrote:
>>> I wouldn't use embperl to accept json. I see embperl as being
>>> designed for HTML output, so I don't really see how it helps when
>>> dealing with json.
>>>
>>> On Fri, Sep 2, 2016 at 11:43 PM, Donavon <donl@mycopanet.com
>>> <mailto:donl@mycopanet.com>> wrote:
>>>
>>> Good to know that there are still some Embperl users out there.
>>>
>>> We have a large SAAS system mainly in Embperl, so our usage of
>>> Embperl is not going away anytime soon.
>>>
>>>
>>> My current question to the Embperl community is:
>>>
>>> *How to accept **application/json?*
>>>
>>> **I know that "Embperl uses CGI.pm internally to process forms
>>> encoded with multipart/form-data" and that get processed into
>>> %fdat.
>>>
>>> Is there a way to disable this behavior dynamically per page to
>>> accept application/json data.
>>>
>>> Thanks,
>>> ~Donavon
>
> Perhaps I am misunderstanding the scenario you are dealing with, but I
> use json in my regular Embperl-based website all the time to
> communicate with the client side Javascript. On the client side I just
> use JSON.parse and JSON.stringify to decode/encode objects for sending
> via regular POST calls. And on the server side, I get that data
> through the usual %fdat and decode it using JSON::Parse. This is all
> done using the regular, vanilla Embperl GET/POST. So unless you are
> dealing with some other third party application that you have no
> control over (i.e. something is generating calls that are specifically
> application/json), I don't see why using JSON with Embperl is an
> issue. After all, JSON is really just a way of encoding objects as
> text, like XML.
>
> I also generate application/xml responses using Embperl, just set
> $http_headers_out{'Content-type'} to whatever you are using and then
> make sure the actual output matches that format. What I do is have a
> base.epl that figures out what the current request is about (usually
> via a page_type() sub that is redefined in subdirectories using
> Embperl::Object), and then base.epl calls e.g. base_html.epl if it's a
> regular web page, or base_xml.epl if it's going to be an xml response,
> or base_text.epl if it's a simple text response etc.
>
> Sorry, I don't know if I'm completely missing the point, but it's very
> easy to work with json in Embperl. Unless, like I said, you have some
> other application that is actually generating application/json calls,
> and you have no control over that, and you're trying to figure out how
> to get Embperl to even handle those requests... if that's the case,
> then ok, I'm not sure how that would work with %fdat etc.
>
> Neil
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
> For additional commands, e-mail: embperl-help@perl.apache.org
>
Re: EMBPERL: accepting json [ In reply to ]
Donavon wrote:
> If I use Embperl to receive JSON data. That's where the issue
> arises. <script> |
>
> var formData = {"data1":a,"data2":b,"data3":c};
>
> $.ajax(
>
> {dataType:"json",
>
> contentType:"application/json; charset=UTF-8",
>
> url:'/folder1/doSomething1.epl',
>
> data:formData, success:function(response){ CurrentArray=response; } });
> </script>


Ok, so it sounds like you have some control over how the calls are
happening on the client side, is that correct? I don't use JQuery
myself, but fwiw here is roughly how I make an Ajax call using JSON
data. I use a function createRequest that just wraps creating a new
XMLHttpRequest (as well as picking up some exceptions to do with
Microsoft etc - not really important here).

var data = {a: 1, b: 2, c: 3};
var params = 'data=' + encodeURIComponent (JSON.stringify (data));
createRequest();
if (request != null)
{
var url = '/ajax/some_handler.html';
request.open("POST", url, true);
request.setRequestHeader("Content-type",
"application/x-www-form-urlencoded");
request.setRequestHeader("Content-length", params.length);
request.setRequestHeader("Connection", "close");
request.onreadystatechange = the_callback_function;
var result = request.send (params);
}

So I dunno if it's relevant, but I don't use "application/json" as the
content type, but rather "application/x-www-form-urlencoded". On the
server side, I use a .html page, but that could be anything you set up
to be handled by Embperl in your Apache config. It doesn't have to
actually produce html code, obviously, it could respond entirely in JSON
or XML or whatever you want to set. But that's not really relevant - the
important thing is that I am able to receive the call just fine, and it
contains the JSON data in a form field called 'data' (arbitrary name,
obviously, whatever you want to call it). I access it via %fdat as usual.

So, if you are in control of how the call happens from the client side,
then it seems to me there's no reason why you can't pass JSON to
Embperl, and there's no reason why it has to be "application/json". Like
I said I dunno if the content type is the issue, but just a demo of a
method that I use, that works fine.

Hope that helps,

Neil

---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org
Re: EMBPERL: accepting json [ In reply to ]
Donavon,



Could you try this script (as the doSomething.epl of your $.ajax()
example) ?




[.-
use Data::Dumper;

$req = shift;

print OUT "fdat : ".Dumper(%fdat);
-]





Just to be sure %fdat is empty.



---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org
Re: EMBPERL: accepting json [ In reply to ]
> [.-
> use Data::Dumper;
>
> $req = shift;
>
> print OUT "fdat : ".Dumper(%fdat);
> -]

This will print in a terminal.


Better :


[.-
use Data::Dumper;

$req = shift;

warn "fdat : ".Dumper(%fdat);
-]
To see the result in apache's error.log


---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org
Re: EMBPERL: accepting json [ In reply to ]
That is how I generally make calls.. ie;
request.setRequestHeader("Content-type",
"application/x-www-form-urlencoded");

However this is a new world and when using pre-done libraries, outside
contractors or creating a client API, using
'request.setRequestHeader("Content-type",
"application/x-www-form-urlencoded");' is not always possible.

A lot of things RESTful seem to use application/json.






On 9/8/2016 12:22 PM, Neil Gunton wrote:
> Donavon wrote:
>> If I use Embperl to receive JSON data. That's where the issue
>> arises. <script> |
>>
>> var formData = {"data1":a,"data2":b,"data3":c};
>>
>> $.ajax(
>>
>> {dataType:"json",
>>
>> contentType:"application/json; charset=UTF-8",
>>
>> url:'/folder1/doSomething1.epl',
>>
>> data:formData, success:function(response){ CurrentArray=response; } });
>> </script>
>
>
> Ok, so it sounds like you have some control over how the calls are
> happening on the client side, is that correct? I don't use JQuery
> myself, but fwiw here is roughly how I make an Ajax call using JSON
> data. I use a function createRequest that just wraps creating a new
> XMLHttpRequest (as well as picking up some exceptions to do with
> Microsoft etc - not really important here).
>
> var data = {a: 1, b: 2, c: 3};
> var params = 'data=' + encodeURIComponent (JSON.stringify (data));
> createRequest();
> if (request != null)
> {
> var url = '/ajax/some_handler.html';
> request.open("POST", url, true);
> request.setRequestHeader("Content-type",
> "application/x-www-form-urlencoded");
> request.setRequestHeader("Content-length", params.length);
> request.setRequestHeader("Connection", "close");
> request.onreadystatechange = the_callback_function;
> var result = request.send (params);
> }
>
> So I dunno if it's relevant, but I don't use "application/json" as the
> content type, but rather "application/x-www-form-urlencoded". On the
> server side, I use a .html page, but that could be anything you set up
> to be handled by Embperl in your Apache config. It doesn't have to
> actually produce html code, obviously, it could respond entirely in
> JSON or XML or whatever you want to set. But that's not really
> relevant - the important thing is that I am able to receive the call
> just fine, and it contains the JSON data in a form field called 'data'
> (arbitrary name, obviously, whatever you want to call it). I access it
> via %fdat as usual.
>
> So, if you are in control of how the call happens from the client
> side, then it seems to me there's no reason why you can't pass JSON to
> Embperl, and there's no reason why it has to be "application/json".
> Like I said I dunno if the content type is the issue, but just a demo
> of a method that I use, that works fine.
>
> Hope that helps,
>
> Neil


---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org
Re: EMBPERL: accepting json [ In reply to ]
Donavon wrote:
> That is how I generally make calls.. ie;
> request.setRequestHeader("Content-type",
> "application/x-www-form-urlencoded");
>
> However this is a new world and when using pre-done libraries, outside
> contractors or creating a client API, using
> 'request.setRequestHeader("Content-type",
> "application/x-www-form-urlencoded");' is not always possible.
>
> A lot of things RESTful seem to use application/json.

Ok, but if you're interested in debugging the reason why you aren't
getting the results you expect, then I thought it might be useful for
you to see how it can work successfully. Maybe it's the content type,
maybe something else, but when something doesn't work, you can take an
example that you know does work and go from there. Get a working
example, then gradually change things over to the way you want to do it,
testing at each step, until it stops working. Then at least you know
what step it was that broke it. Just an idea.

Neil


---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org
Re: EMBPERL: accepting json Working Example [ In reply to ]
This is what I was able to get working...

I used a regular javascript "XMLHttpRequest()" rather than the jQuery
"|$.ajax({||});" from my original request.
|

General Requirements:

- Directory needs to be able to use an .htaccess file

- perl JSON Module needs to be installed


Suggested changes and modifications are greatly appreciated. I still
need to get GET, PATCH and DELETE working.

Thank You and I HOPE this comes in handy to others!!!
~Donavon


*.htaccess*

<Files "json-submit.epl">

EMBPERL_OPTIONS 256

</Files>




*base.html*

<!DOCTYPE html>

<html lang="en">

<head>

<title> </title>

</head>

<body >

Hello World!!!

<script>

var url = "json-submit.epl";

var data = {

"firstName" : "Joe1",

"lastName" : "Schmoe1"

};

var callback = function (data) {

var json = JSON.parse(data.responseText);

alert(JSON.stringify(json));

};

var request = new XMLHttpRequest();

request.open("POST", url);

request.onreadystatechange = function() {

if(request.readyState === 4 && callback) {

callback(request);

}

};

request.setRequestHeader('Content-Type', 'application/json;
charset=UTF-8');

request.send(JSON.stringify(data));

</script>

</body>

</html>






*json-submit.epl*

[.-

use JSON; # imports encode_json, decode_json,
to_json and from_json.

# to mimic proper Boolean data type

use constant false => 0;

use constant true => 1;

%param = ();


$returnHash{method} = $req_rec->method();

# params from json

%param = ();

use CGI;

$q = new CGI;

if($req_rec->method() eq 'POST') {

$postData = decode_json($q->param('POSTDATA'));

%param = %$postData;

$return = true;

}

elsif($req_rec->method() eq 'PUT') {

$putData = decode_json($q->param('PUTDATA'));

%param = %$putData;

$return = true;

}

elsif($req_rec->method() eq 'GET') {

# ????????????????????????????????

$return = true;

}

elsif($req_rec->method() eq 'PATCH') {

# ????????????????????????????????

$return = true;

}

elsif($req_rec->method() eq 'DELETE') {

# ????????????????????????????????

$return = true;

}

else {

$return = false;

}

$returnHash{param} = $param;

%{$returnHash{param}} = %param;

$return = true;

$json{return} = $return;

$json{returnHash} = \%returnHash;

$escmode = 0;

print OUT encode_json(\%json);

-]



On 9/8/2016 10:04 AM, Donavon wrote:
>
> I agree with all of the responses that Embed perl was made to mainly
> use CGI.pm and multipart/form-data and really shouldn't be used
> outside of that.
>
> BUT As long as there is possibility that it might be able to receive
> application/json data I have to look for a way to do it. It's part of
> my job to look for solutions that work within current limitations.
>
> If every response to this email is "It's not possible" that is
> something I can take to a meeting. If the responses are "You
> shouldn't or it's difficult" then I have to keep searching for a
> solution that is understandable and workable.
>
> I'm willing to pay a small consulting fee or a donation to a charity,
> for assistance in figuring this out.
>
> So what are the suggestions for handling a call like this on a script
> by script basis. I might be possible to limit the scripts accepting
> these calls to specific directories.
>
> |varformData
> ={"data1":a,"data2":b,"data3":c};$.ajax({dataType:"json",contentType
> :"application/json;
> charset=UTF-8",url:'/folder1/doSomething1.epl',data
> :formData,success:function(response){CurrentArray=response;}}); Thank
> You, ~Donavon |
>
>
>
>
>
>
> On 9/4/2016 2:30 AM, Michael Smith wrote:
>> I wouldn't use embperl to accept json. I see embperl as being
>> designed for HTML output, so I don't really see how it helps when
>> dealing with json.
>>
>> On Fri, Sep 2, 2016 at 11:43 PM, Donavon <donl@mycopanet.com
>> <mailto:donl@mycopanet.com>> wrote:
>>
>> Good to know that there are still some Embperl users out there.
>>
>> We have a large SAAS system mainly in Embperl, so our usage of
>> Embperl is not going away anytime soon.
>>
>>
>> My current question to the Embperl community is:
>>
>> *How to accept **application/json?*
>>
>> **I know that "Embperl uses CGI.pm internally to process forms
>> encoded with multipart/form-data" and that get processed into %fdat.
>>
>> Is there a way to disable this behavior dynamically per page to
>> accept application/json data.
>>
>> Thanks,
>> ~Donavon
>>
>>
>>
>>
>