- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Using JSON in a "GET" HTTP Request
I'm working to interface with our data retrieval engine. I can submit a job perfectly fine using a POST request like this:
request = New HTTP Request(
url( "http://fc8tdbitmapconvs07:11111/daas/" ),
Method( "POST" ),
Json( Load Text File( ctfn ) )
);
data = request << Send;
'data' contains the response from the server and all is well.
-------------------------------------------
However, when I try and check on the status of the running job with a 'GET' request the json does not get included in the HTTP request to the server:
Attempt#1:
request2 = New HTTP Request(
url( "http://fc8tdbitmapconvs07:11111/daas/status/" ),
Method( "GET" ),
headers( {"Content-Type:application/json"} ), // add your custom headers
Json( Load Text File( ctfn2 ) )
);
data2 = request2 << Send;
Attempt#2
request2 = New HTTP Request(
url( "http://fc8tdbitmapconvs07:11111/daas/status/" ),
Method( "GET" ),
headers( {"Content-Type:application/json"} ) // add your custom headers
);
request2 <<Json( Load Text File( ctfn2 ) );
data2 = request2 << Send;
In both cases the JSON fails to load. The header information makes it to the server just fine but the spot where the JSON should be in the request is empty. What am I missing?
Thanks
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Using JSON in a "GET" HTTP Request
This feature (using "GET" while sending JSON) should be available in JMP 15.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Using JSON in a "GET" HTTP Request
"GET"
and "POST"
are two different HTTP request methods (https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods)
"GET" typically reads data from a server while
"Post" typically submits data to a server.
These are Web Server/Web Service defined outside of JMP/JSL
In your first example, you are "POST"-ing (aka submitting) data to "http://fc8tdbitmapconvs07:11111/daas/" and telling the service that ctfn is the JSON content to use.
In Attempt#1, the goal is "GET"-ting the status of a running job. I'm not sure what the service is, but if the endpoint is "http://fc8tdbitmapconvs07:11111/daas/status/", then you'd want something like:
request2 = New HTTP Request(
url( "http://fc8tdbitmapconvs07:11111/daas/status/" ),
Method( "GET" )
);
data2 = request2 << Send;
Since you wouldn't be submitting anything to the server in a GET.
Additionaly, "Content-Type:application/json" is used to describe the content you are sending (not really appropriate in a GET since you are recieving data and probably ignored by the web server)
Content-Type: headers are what you are sending (these are automatically set by HTTP Request)
Accept: headers are what you tell the web server you'd like.
request << Get MIME Type
will tell you what the web server sent. (most web servers set this, but it can be empty)
Keep in mind, too that after any
request << Send
You can do
request << Get Status; //this is the http status code
request << Get Status Message; //this is the message from the server
to investigate any error message the Web Service emits.
HTH
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Using JSON in a "GET" HTTP Request
Thank you for the quick response. According to the developer who wrote the
REST API the JSON is required. Here's the working version in Python
status_info = get(
'http://fc8tdbitmapconvs07:11111/daas/status/',
json={'_id': '5cc311a97925b1000ce4fd54', 'include_complete':
True}
).json()
>> the long number in red is the job number which of course varies. This
bit works fine running in a python notebook or running inside JMP using the
following JSL. But, how do I get it to work with the HTTP Request protocol?
Thanks!
-----------------------------------------------------------------------------------------------------------------------------
Python Init();
Python Execute(
{x},
{status_info},
"
import getpass
from io import BytesIO
from time import sleep
import pandas as pd
from requests import get, post
status_info = get(
'http://fc8tdbitmapconvs07:11111/daas/status/',
json={'_id': '5cc311a97925b1000ce4fd54', 'include_complete':
True}
).json()
"
);
Python Term();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Using JSON in a "GET" HTTP Request
Is the JSON embedded in a request header? (Dropbox, Onedrive, and many others do that)
The JSON argument in the HTTP Request used in a POST/PATCH/PUT where the content is sent with the JSON content type. It is a "submit" action.
GET are "read" and arguments are either query strings or embeded in a request header.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Using JSON in a "GET" HTTP Request
After reading up on the HTTP Spec, I see that sending data with a GET is discouraged and that servers usually ignore it.
I found this discussion on stackoverflow, which links to the relevant HTTP specs.
Is this statement correct? HTTP GET method always has no message body
It basically boils do to some custom webservice implementations might use it and the spec is pretty nebulous about it.
Maybe I can get something in for JMP 15 if the need still exists.
Are there any other avenues to interact with this serviece?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Using JSON in a "GET" HTTP Request
Bryon,
Thank you for the quick reply. I'm working directly with the developer for the REST API and packaging the JSON in a GET request is their documented way of requesting data. You're correct that the spec is not clear and packaging JSON in a GET request is what is taught in some CS curriculums. In this instance the idea is to pass in a job number which will return either a code indicating the job is not yet complete (poll & response) or a code indicating that it is complete, the data file names and a zip file containing these files. If you could get something into JMP 15 that would be very helpful.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Using JSON in a "GET" HTTP Request
One last thing (or 2). can the Job Number, etc be passed as a query string parameter (or even JSON can be embedded in the request header)
and 2, be sure to add the get with a "body" to the wish list. That way we can keep track and you can be notified when it's there.
Thanks.
-Bryan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Using JSON in a "GET" HTTP Request
This feature (using "GET" while sending JSON) should be available in JMP 15.