APL using CURL
7 posts
• Page 1 of 1
APL using CURL
Hi!
Are there some documentation or example about APL using CURL?
How can I read/take data from url and put into an apl variable?
The data is JSON. I need put it into apl variables to update my apl files.
Sending from my system/MiServer to app using var←⎕cmd "CURL command ...." is ok. My difficulty is in the opposite way.
Could someone help me, please?
Cheers,
Marco
Are there some documentation or example about APL using CURL?
How can I read/take data from url and put into an apl variable?
The data is JSON. I need put it into apl variables to update my apl files.
Sending from my system/MiServer to app using var←⎕cmd "CURL command ...." is ok. My difficulty is in the opposite way.
Could someone help me, please?
Cheers,
Marco
- Gantois
- Posts: 90
- Joined: Thu Apr 17, 2014 9:44 am
Re: APL using CURL
Can you easily share a test case (i.e. simplified example) of what you are trying that isn't working? I'm not an expert and, if it matters, I'm using a Mac.
- petermsiegel
- Posts: 159
- Joined: Thu Nov 11, 2010 11:04 pm
Re: APL using CURL
Hi Peter,
Thanks for your response. Im Marco Gantois from Brazil. Nice to meet you.
I think my problem can be solved with a similar function structure as MiServer Calss but without returning to browser, i.e:
:Class apitest: blank
:Field Public action
:Field Public urldata
∇ Render req; response
:Access Public
response←''
DoAction
req.Return response
∇
∇ DoAction
:Select action
:Case '01'
....
:Case '02'
....
:EndSelect
∇
:EndClass
Thanks,
//MG
Thanks for your response. Im Marco Gantois from Brazil. Nice to meet you.
I think my problem can be solved with a similar function structure as MiServer Calss but without returning to browser, i.e:
:Class apitest: blank
:Field Public action
:Field Public urldata
∇ Render req; response
:Access Public
response←''
DoAction
req.Return response
∇
∇ DoAction
:Select action
:Case '01'
....
:Case '02'
....
:EndSelect
∇
:EndClass
Thanks,
//MG
- Gantois
- Posts: 90
- Joined: Thu Apr 17, 2014 9:44 am
Re: APL using CURL
Hi Marco,
If I understand your question, you'd like to be able to return JSON data from MiServer in response to a request from curl?
I also see you're using MiServer version 2, so I'll respond with examples using that version rather than Version 3.
The first question is: Is your data static (not computed dynamically)? If so, you can simply put the JSON data in a .json file in your MiSite and any client (like curl) can just retrieve it.
So if you have a file, let's call it data.json for this example, that looks like:
Then it can be retrieved just by asking for the file:
If your JSON data is dynamic, then you can write a MiPage that returns the data.
This line sets the content-type header and just returns the raw data
and this line tells MiServer not to do any additional processing on the response
Then the page can be retrieved using curl as follows:
I hope this helps!
/Brian
If I understand your question, you'd like to be able to return JSON data from MiServer in response to a request from curl?
I also see you're using MiServer version 2, so I'll respond with examples using that version rather than Version 3.
The first question is: Is your data static (not computed dynamically)? If so, you can simply put the JSON data in a .json file in your MiSite and any client (like curl) can just retrieve it.
So if you have a file, let's call it data.json for this example, that looks like:
- Code: Select all
{
"name":"Drake Mallard",
"age":42
}
Then it can be retrieved just by asking for the file:
⎕SH'curl localhost:8080/data.json'
{
"name":"Drake Mallard",
"age":42
}
If your JSON data is dynamic, then you can write a MiPage that returns the data.
- Code: Select all
:Class jsonPage : MildPage
∇ Render req;jsonData
:Access Public
jsonData←⎕NS '' ⍝ create a namespace
jsonData.(name age)←'Drake Mallard' 42 ⍝ populate with some data
jsonData←⎕JSON jsonData ⍝ convert to JSON format
'content-type' 'application/json'req.Return jsonData
req.Response.NoWrap←1 ⍝ don't "wrap" the page
∇
:EndClass
This line sets the content-type header and just returns the raw data
- Code: Select all
'content-type' 'application/json'req.Return jsonData
and this line tells MiServer not to do any additional processing on the response
- Code: Select all
req.Response.NoWrap←1 ⍝ don't "wrap" the page
Then the page can be retrieved using curl as follows:
⎕SH'curl localhost:8080/jsonPage'
{"age":42,"name":"Drake Mallard"}
I hope this helps!
/Brian
-
Brian|Dyalog - Posts: 120
- Joined: Thu Nov 26, 2009 4:02 pm
- Location: West Henrietta, NY
Re: APL using CURL
Hi Brian, How are you?
Thanks for your response.
Yes, I am using MiServer version 2 and you gave me informations extremely useful, that I didn't know, and certainly I will use: "convert to JSON format" (very nice).
I'm develloping an endpoint to receive informations from an app. This app (PHP/MySql) send a JSON to MiServer (post method) with some pre-defined fields, one of them is a "transaction_type".
I need get these fields from JSON to apl variables and then update my components files according to type of transaction.
I think you've already clarified one of my doubt:
1. I do not need give back info from MiServer to app. The answer is:
req.Response.NoWrap←1, isn't it?
2. JSON to apl variables.
I was thinking to devellop functions to do this but your response about APL to JSON make me think that there are functions or instructions to do this (JSON to APL) that could help me avoiding unnecessary develloping. Are there this opposite way?
Thanks very much,
Cheers,
Marco
Thanks for your response.
Yes, I am using MiServer version 2 and you gave me informations extremely useful, that I didn't know, and certainly I will use: "convert to JSON format" (very nice).
I'm develloping an endpoint to receive informations from an app. This app (PHP/MySql) send a JSON to MiServer (post method) with some pre-defined fields, one of them is a "transaction_type".
I need get these fields from JSON to apl variables and then update my components files according to type of transaction.
I think you've already clarified one of my doubt:
1. I do not need give back info from MiServer to app. The answer is:
req.Response.NoWrap←1, isn't it?
2. JSON to apl variables.
I was thinking to devellop functions to do this but your response about APL to JSON make me think that there are functions or instructions to do this (JSON to APL) that could help me avoiding unnecessary develloping. Are there this opposite way?
Thanks very much,
Cheers,
Marco
- Gantois
- Posts: 90
- Joined: Thu Apr 17, 2014 9:44 am
Re: APL using CURL
Hi Marco,
If your endpoint doesn't need a user interface (like a browser), then you might want to consider Jarvis, which is the successor to JSONServer. Jarvis/JSONServer makes it extremely easy for apps/clients to exchange data with Dyalog APL. We've done a number of webinars about JSONServer and microservices in Dyalog. If this sounds interesting to you, please contact me directly and we can set up a time for me to show you more about Jarvis.
/Brian
If your endpoint doesn't need a user interface (like a browser), then you might want to consider Jarvis, which is the successor to JSONServer. Jarvis/JSONServer makes it extremely easy for apps/clients to exchange data with Dyalog APL. We've done a number of webinars about JSONServer and microservices in Dyalog. If this sounds interesting to you, please contact me directly and we can set up a time for me to show you more about Jarvis.
/Brian
-
Brian|Dyalog - Posts: 120
- Joined: Thu Nov 26, 2009 4:02 pm
- Location: West Henrietta, NY
Re: APL using CURL
Ok Brian,
I have already sent an email to you,
Thanks
Marco
I have already sent an email to you,
Thanks
Marco
- Gantois
- Posts: 90
- Joined: Thu Apr 17, 2014 9:44 am
7 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 0 guests
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group