Getting stuff via HTTP POST for the semi-n3wb
-
The good news: I've been granted access to a vast wonderland of streaming data that will make all my dreams come true. The bad news: I don't know how to access it. HTTP POST and JSON details inside... This really boils down to asking the basics of how to pull data via HTTP POST. I'm a journalist with ancient rogramming knowledge. (When I program, I do it in C, if that gives you a sense.) The data I'm hoping to access is fairly simple stuff: 12 data fields, nothing terribly complex. The one I'm going to be filtering by, to begin with is just a 6-hexdigit number. (Call this field "numhex." Call the others "field2", "field3", etc.) What I'd like to do is pull down all data where numhex is a member of a small set, say, {aaaaaa, abaaa1, caaaa3} What I've been told is that the data is gettable via HTTP POST, and the output format is JSON. I've also been told that a query to the endpoint will have this packaged in the HTTP POST: "user=user_API&password=password&format=json". I got as far as downloading cURL before my head exploded. Can anyone give me a quick step-by-step primer for how to get access to the sweet, sweet data? Thanks much!
-
Answer:
Is there a way to filter the data on the server, or do you have to do it on the client? On the client side you can use cURL and http://stedolan.github.io/jq/ in combination to do this. The commandlines below may need to be tweaked to work on Windows - I'm testing on Mac. To fetch the data and format it in a human-readable way: $ curl --data "user=user_API&password=password&format=json" http://link.to.endpoint | jq . To do the actual filtering, something like: $ curl --data "user=user_API&password=password&format=json" http://link.to.endpoint | jq 'map(select(.numhex == "aaaaaa" or .numhex == "abaaa1" or .numhex == "caaaa3"))' Ideally, you could do the filtering server-side, but the provider would have to tell you how to request that in a way specific to their service. It would probably involve changing either the URL or the data you put in the HTTP POST to specify the filter.
cgs06 at Ask.Metafilter.Com Visit the source
Other answers
This depends on the language you want to work with; in PHP it would look something like following (returns an array containing all data): <?php $sweet_sweet_data = json_decode( file_get_contents( "http://domain.com/api?user=user_API&password=password&format=json" ) ); ?> Then just loop through the data and filter to your hearts content.
axismundi
Maybe using the https://chrome.google.com/webstore/detail/postman/fhbjgbiflinjbdggehcddcbncdddomop?hl=en will be a little easier for you than using Curl? It lets you just paste in the body you want to send via your POST request, e.g. "user=user_API&password=password&format=json" assuming you have a valuid user_API and password. The thing is, "user=user_API&password=password&format=json" looks like the kind of thing that normally goes in a URL (an https URL) rather than a POST body. Can you give us the actual URL you are trying to post to? (Also, I don't get how streaming comes into play here. What you're doing is making a basic http request – it means you'll open a socket, make the request, get the response in its entirely, then close the socket. When you stream, you usually leave the socket open and chunks come down a bit at a time.)
ignignokt
The thing is, "user=user_API&password=password&format=json" looks like the kind of thing that normally goes in a URL (an https URL) rather than a POST body. There is nothing surprising about this. Payloads in a POST request are URL-encoded all the time.
invitapriore
What I'd like to do is pull down all data where numhex is a member of a small set, say, {aaaaaa, abaaa1, caaaa3} What I've been told is that the data is gettable via HTTP POST, and the output format is JSON. A POST request is a pretty general thing. I doubt the service you will be using returns all of the data all of the time, so you probably need to either request a dynamically generated URL or put something in the POST body to tell the server what data to give you. This is not something that can be answered in general, you'll have to ask the people providing the service for more details.
Dr Dracator
Thanks for the answers so far... I'd rather not post the actual URL, but it's of the form https://api.company.com/webservice.php if that helps... I'll get my hands on jq and Postman this evening and play around... thanks for those suggestions. I *assume* the filtering would be on the client side, as it's a fairly large amount of real-time data that I'm looking for, but I'm not 100% sure. As for streams... I know that there exists a stream of data... each object -- numhex is a unique identifier -- is having its attributes constantly updated. Whether I'm tapping the data directly, or a periodically-refreshed database at a a discrete time period, or what, I don't rightly know.
cgs06
Related Q & A:
- Where To Buy Wholesale Semi Precious Beads?Best solution by Yahoo! Answers
- Is there a web site you can post comments about a business that sells products via the web. Like the BBB?Best solution by Yahoo! Answers
- How to delete stuff from the http:// bar?Best solution by Yahoo! Answers
- How can I send a mail via Philippine post?Best solution by pe.usps.com
- What's a good free site to post stuff on?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.