pikelang / Pike

Pike is a dynamic programming language with a syntax similar to Java and C. It is simple to learn, does not require long compilation passes and has powerful built-in data types allowing simple and really fast data manipulation.
http://pike.lysator.liu.se/
Other
194 stars 34 forks source link

PUT Requests don't work, they just crash #31

Closed TheOnlyArtz closed 5 years ago

TheOnlyArtz commented 5 years ago

I'm trying to establish a PUT HTTP request since there's no PATCH (Why there's no patch too? :) )

        response = Protocols.HTTP[lower_case(method) + "_url"](uri,"", data, headers);

image

What may be the cause? I don't think I'm doing anything wrong

agehall commented 5 years ago

You are using the put_url() method wrong. Please read the API docs for it.

The way you try to use the convenience methods is very bad coding practice since their signatures are all different. If you read the module documentation, it should be obvious that you are better off using do_method() instead.

Also, as I have stated before, issues are typically for bugs. Avoid using GitHub issues to ask general questions - use the mailing lists instead.

TheOnlyArtz commented 5 years ago

I don't get the mailing lists can I get relevant info? like, how to subscribe and ask questions from them

agehall commented 5 years ago

http://pike.lysator.liu.se/forums/

TheOnlyArtz commented 5 years ago

You are using the put_url() method wrong. Please read the API docs for it.

The way you try to use the convenience methods is very bad coding practice since their signatures are all different. If you read the module documentation, it should be obvious that you are better off using do_method() instead.

Also, as I have stated before, issues are typically for bugs. Avoid using GitHub issues to ask general questions - use the mailing lists instead.

Alright, btw, I don't get how I'm using the PUT wrong, I don't have a file so I'm just sending an empty string and I don't have a connection so I don't send anything at all, I read the documentation and filled the parameters correctly. the query variables are something like

(["topic": "test"])

the headers are something like

(["Authorization": "TOKEN"])

So I don't really get what I'm doing wrong.

agehall commented 5 years ago

Read the documentation! Normally people complain about poor docs in Pike and they are usually right, but in this case there is nothing wrong with the docs.

Compare

.Query put_url(string|Standards.URI url, void|string file, void|mapping(string:int|string|array(string)) query_variables, void|mapping(string:string|array(string)) request_headers, void|Protocols.HTTP.Query con)

to for example

.Query get_url(string|Standards.URI url, void|mapping(string:int|string|array(string)) query_variables, void|mapping(string:string|array(string)) request_headers, void|Protocols.HTTP.Query con).

See? The signatures are vastly different. In the first instance query variables are the third argument and in the second case they are the second argument.

TheOnlyArtz commented 5 years ago

Right! and I'm passing the query variables as the 3rd argument! I'm sorry I didn't show you the whole relevant code but it looks like

      if (lower_case(method) != "put")
        response = Protocols.HTTP[lower_case(method) + "_url"](uri, data, headers);
      else
        response = Protocols.HTTP[lower_case(method) + "_url"](uri,"", data, headers);

I am passing the query variables as the 3rd argument! So, whenever PUT is being requested the data (query variables) will get passed as the 3rd argument

TheOnlyArtz commented 5 years ago

Okay update, I've managed to send put request successfully, sorry for everything, from now and then I will use the mailing list! Last: can I call PATCH method when using do_method?

agehall commented 5 years ago

Yes, do_method() is the method you should be using for this type of thing. And it doesn't really care about what verb you use.

TheOnlyArtz commented 5 years ago

Alright, that sounds way better! thank you, checking it out right now.