kanewilliam7777 has asked for the wisdom of the Perl Monks concerning the following question:
Hello all,
I have to implement REST API conecpt in PERL
So I need sample localhost request & response code using REST concept.
Please anybody have sample code.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Sample REST request & response code
by marto (Cardinal) on Sep 06, 2018 at 06:41 UTC | |
| [reply] | |
|
Re: Sample REST request & response code
by 1nickt (Canon) on Sep 06, 2018 at 11:41 UTC | |
Hi, there's sample code in the documentation of any decent CPAN module, in the SYNOPSIS as well as in the test files. Larger platforms such as web application servers typically offer expansive documentation. Which have you looked at so far? I recommend using Dancer2 to serve your REST API, and you might like REST::Client for making requests to it. Server: Client:
Hope this helps!
The way forward always starts with a minimal test.
| [reply] [d/l] [select] |
|
Re: Sample REST request & response code
by thanos1983 (Parson) on Sep 06, 2018 at 08:40 UTC | |
Hello kanewilliam7777, Some time ago (not more than 5-6 months) I wrote a small module for doing (GET, POST, DELETE, PUT and POST file). It should all what you need when you modify it to your requirements. See the repo in GIT thanos1983/Perl5-MyClientRest-ClientRest. Sample of how to call the module:
You need to configure it to your needs but it should be more than a good starting point. The module is very simple so it should be straight forward for modifications. Hope this helps, BR.
Seeking for Perl wisdom...on the process of learning...not there...yet!
| [reply] [d/l] [select] |
by Aldebaran (Curate) on Sep 07, 2018 at 00:14 UTC | |
hi thanos I'm interested in replicating this. Could $host be a remote website with which I currently use sftp?
This is what I've been using to try to start up a conversation with a remote server and it's either not the right thing or I don't know how to script it. I looked at your repo. Can you say a few words as to what a Snippet is? Thanks, | [reply] [d/l] |
by thanos1983 (Parson) on Sep 07, 2018 at 08:54 UTC | |
Hello Aldebaran, The quick answer to your question Could $host be a remote website with which I currently use sftp? is yes it can. The longer version and my recommendation is not to use HTTP/HTTPS to upload files. My module is a customization which in the background uses REST::Client to do all the communication. Further analysis why I do not recommend to use HTTP/HTTPS for uploading files?
Reference Source HTTPS or SFTP – which is best?. SFTP is a protocol designed for this purposes (file transfer) using SSH connections. If you ask my opinion I would continue using the Net::SFTP::Foreign module but with a small modification, I would use SSH keys instead of sending username and password. If you want to see a sample of code on how to use SSH keys connection Re: Net::SFTP::Foreign Password Authentication Hangs (UPDATED). There are many reasons on why to use SSH keys instead of password, the really fast answer is because it is way more secure and less communications between client/server. To conclude, yes it is possible to send a file through HTTP/HTTPS (SSL encryption) with the help of my module that uses REST::Client or directly modify it for your needs, but I would not recommend it unless if you did not had the ability to use SSH strictly HTTP/HTTPS. You also asked what is Snippet is the name that I used for the data that is send from the server. Let me know if you have more questions. BR / Thanos
Seeking for Perl wisdom...on the process of learning...not there...yet!
| [reply] [d/l] [select] |
|
Re: Sample REST request & response code
by Anonymous Monk on Sep 06, 2018 at 06:35 UTC | |
| [reply] | |