HOWTO fetch internet resources
Is there a way in mojo that can be used for fetching websites, get and post?
12 Replies
There is not a built-in way to do it, but you can use the Python interop to use a Python library to do requests for you. In the future the community or Modular may build a library to do it in Mojo natively, but currently Python interop is the only way.
Thanks, I tried using
request
in Jupyter book it is fine, but in file.mojo
it gave an error:
I got:
![No description](https://cdn.answeroverflow.com/1155950527427907605/image.png)
Could it be because of a top level variable?
@Kushagra @Hasan Yousef @Alex Kirchhoff
Ok, I'll try and let you know
@Hasan Yousef let http = Python.import_module("requests") , add this under main
it works , post i didnt check
I thought of exactly the same
![No description](https://cdn.answeroverflow.com/1155961782704296007/image.png)
Thanks @roopesh puthalath @Kushagra and @Alex Kirchhoff , I deeply appreciate it. but have a question here, will this make the program speed the same as python or it will be supercharged by mojo?
@Hasan Yousef here the speed is driven by the latency of your fetching.
Only the parts written in Mojo will experience any speed-up.
This is because you are shadowing the stdlib module 'python'. Don't create a "python.mojo" file as that will confuse mojo (or Python).