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

Fixes #276

Merged
merged 3 commits into from
Oct 6, 2020
Merged

Fixes #276

merged 3 commits into from
Oct 6, 2020

Conversation

Andy-Python-Programmer
Copy link
Contributor

@Andy-Python-Programmer Andy-Python-Programmer commented Sep 15, 2020

I was unable to do this fix as I was buzy. Now I have done them.

def setup():
    size(400, 400)

def draw():
    background(0)
    
    example = http_get("https://example.com")
    print(example.text)

run()

I have made it a class so that we can do example.text or example.json (for json). If we would have checked each of the lines for example decode json if it startswith("{") and endswith("}") then it will be a very slow process.

@arihantparsoya
Copy link
Member

can you be a bit more descriptive about this PR?

It would be great if you could refer to the related issues and PRs.

@Andy-Python-Programmer
Copy link
Contributor Author

@parsoyaarihant So the issue was that the get request from now only returned json so it failed it the result is not in json format. This pr fixes that issue. No related issues are there.

@arihantparsoya
Copy link
Member

I have few comments about this module:

  1. If the request failed, it should be more descriptive about why the request failed. it should give the status codes: https://www.restapitutorial.com/httpstatuscodes.html
  2. If you are making a class based, implementation, all the functions should use that implementation. Not just http_get().
  3. What about asynchronous calls? Should we pass a callback function for asynchronous requests? : https://p5js.org/reference/#/p5/httpGet

@Andy-Python-Programmer
Copy link
Contributor Author

@parsoyaarihant for the 2. Point. I think we only need class for http_get we do not need class based implementation for http_post. And I will take a look at the http error codes.

@Andy-Python-Programmer
Copy link
Contributor Author

Andy-Python-Programmer commented Sep 27, 2020

Hi @parsoyaarihant about the error codes what we can do is just simply remove the try and except as URL lib will auto throw an exception and it will contain the respected http error codes. What do you think?

@arihantparsoya
Copy link
Member

We can do that, I think the documentation and examples should also contain the try and except statements to explain how to use this API

@arihantparsoya arihantparsoya merged commit 7565829 into p5py:master Oct 6, 2020
@arihantparsoya
Copy link
Member

Thanks

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

Successfully merging this pull request may close these issues.

3 participants