Computer Related > Using REST APIs Miscellaneous
Thread Author: smokie Replies: 13

 Using REST APIs - Kevin
>..but that is, I presume, stage 2.

Correct. Stage 1 is to get the data you want from the server via the command line.

Personally, I'd get http working since it's more user friendly and the API examples in your link all use http which makes it easier. As long as you have the directories where the python executable and http live in your PATH you should just be able to call http from the command line.

When you call http from the command line does it fail with an error or just say that it is not a valid command?

Here's a guide to installing it correctly tinyurl.com/ybe3l3jq

With the latest versions of python I'm pretty sure that there's an option to add the correct directories to your PATH automatically.

On my windows laptop the following is part of my PATH for python C:\Users\kevin\AppData\Local\Programs\Python\Python37-32\Scrip
ts\;C:\Users\kevin\AppData\Local\Programs\Python\Python37-32\
;


>..it seems that the GET command is a parameter of the Curl command, so I can run it all in one go in my command prompt.

GET is one of the basic parameters you need to give to http or curl. It tells them what funtion you want to perform (ie. GET data or PUT data etc.)

Once you've got the http command doing what you want you can then either embed that command directly into the perl script (perl can call any command as if it had been called from a command line) or you can use perl itself to fetch the data from the server. If you want perl to fetch the data you will need to install the LWP::Simple or LWP::UserAgent module. Perl has thousands of 'modules' (add-on library fuctions that give extra functionality). I would recommend just embedding the working http command, a) because you know it's working and can execute it via command line to test it, and b) you won't need to learn the LWP:: syntax.

In either case, the data returned is available within the script so you can manipulate and output it in any way you want.

>I feel I am probably pushing beyond reasonableness in my request here, given the difficulty I am having getting
>my head round this. So please say so if I am.

If you've already got curl to connect, authenticate and return meaningful data you're halfway there.
 Messages Author Date
 Using REST APIs new smokie 10 Jan 19 08:57
 Using REST APIs new Kevin 10 Jan 19 20:32
 Using REST APIs new smokie 11 Jan 19 09:16
 Using REST APIs new Kevin 11 Jan 19 23:27
 Using REST APIs new smokie 12 Jan 19 00:32
 Using REST APIs new smokie 12 Jan 19 09:03
 Using REST APIs new Kevin 12 Jan 19 22:34
 Using REST APIs new smokie 13 Jan 19 18:57
 Using REST APIs new Kevin 13 Jan 19 20:51
 Using REST APIs new Kevin 18 Jan 19 23:21
 Using REST APIs new smokie 19 Jan 19 08:11
 Using REST APIs new Kevin 19 Jan 19 23:11
 Using REST APIs new smokie 19 Jan 19 23:46
 Using REST APIs new smokie 8 Feb 19 08:15
Latest Forum Posts