Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

post vs put #11

Open
ufobat opened this issue Jul 4, 2018 · 3 comments
Open

post vs put #11

ufobat opened this issue Jul 4, 2018 · 3 comments

Comments

@ufobat
Copy link
Contributor

ufobat commented Jul 4, 2018

Hi,

I am using this module to talk to a REST API. Some API endpoints are available with the PUT method, some are available with the POST method. While talking to the REST API the content to be sent is in a variable, for both HTTP methods.

I wanted to know if you have any suggestions to make it more easy for me, or maybe if you considder making POST and PUT more similar?

https://github.com/CurtTilmes/perl6-libcurl/blob/master/lib/LibCurl/HTTP.pm6#L29-L38

@CurtTilmes
Copy link
Owner

I'm not quite sure what you are asking for. The current code follows the libcurl model.

Could you provide an example of how you currently call it and how you would like to call it? Or better yet, a suggested patch?

@ufobat
Copy link
Contributor Author

ufobat commented Jul 6, 2018

I need to say that i'm unfortunately not familiar with libcurl; that's why i am asking on your optionion before making a nonsense pull request.

What I want to point out is that the signatures (or semantics) for the 2 methods, PUT and POST, are different.

When I am using curl on the command line put vs post looks like this:

$ curl -X POST -d '{"json": "yeah"}' http://example.com
$ curl -X PUT  -d '{"json": "yeah"}' http://example.com

I am looking for the same interchangeability in this library. What I want to do is sending $content sometimes via put and sometimes via post. If I understood it corretly, in the current version it's just possible to send $content via POST and the content of a file ($filename) via PUT.

@CurtTilmes
Copy link
Owner

libcurl uses some basic conventions.

postfields implies POST, and sets the type to application/x-www-form-urlencoded but you are free to override it and say to use PUT anyway.

likewise upload implies PUT, but you can override that too.

You can still just call setopt with the right stuff to make it act the way you want it to.

$http.setopt(URL => 'http://example.com',
             postfields => $content,
             customrequest => 'PUT')
      .perform;

or

$http.setopt(URL => 'http://example.com',
             upload => $filename,
             customrequest => 'POST')
      .perform;

If you can come up with a good calling sequence, we could make LibCurl::HTTP multi methods for PUT and POST that could set them for you if that would help. Patches welcome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants