问题
Is it possible to send query parameters via POST or GET to a Google Colab notebook? (And also have the response be either plaintext or structured json)
- How to retrieve the query in Colab?
- How do you sanitize or suppress the other output so that only plaintext or json is returned to the endpoint call?
回答1:
You can make direct HTTP requests to the backend from FE Javascript. Here's an example notebook.
Reproducing the key bits:
A webserver can be started on the kernel to serve up arbitrary resources.
The client needs to reference the resource with
https://localhost:{port}
but this will automatically be translated tohttp://localhost:{port}
.By default responses will be cached in the notebook for offline access.
来源:https://stackoverflow.com/questions/56031247/google-colab-as-a-rest-endpoint