What you see is what you REST - how to use it #1277
-
I just played around with @ctrekker REST API #1052 How to get it running: Pluto Server:
Then open / create a notebook which should be the REST server and keep it running (in this example, "rest_test.jl"). Julia client using new Pluto functions:
This works fine for me. As next step, I tried to use the API with standard HTTP requests (this is especially important if the clients are not using Julia):
However, this has not worked for me. Probably I got the request URL wrong, but I could not figure it out what is the correct one. A 3rd use case would be to call the REST API of one notebook from within another notebook. nb = PlutoNotebook("rest_test.jl") But this did not work for me ( Could you please help me with the last 2 use cases? In general the REST API feature is great and I am really looking forward for its release! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
I'm so glad you tried it out, this feedback is very helpful for me! I'm glad the first case works as expected, I have a few notes regarding the 2nd and 3rd. For interacting with a standard HTTP request the requirements are rather specific, which is why I'm currently working on writing some more detailed documentation for the HTTP API itself. I've uploaded the notebook in it's unfinished state here. It currently contains information about how serialization works and the form 2nd Scenario - Manual HTTP RequestsFor example, the following example will use the HTTP API to update import MsgPack
using HTTP
headers = [
"Content-Type" => "application/x-msgpack",
"Accept" => "application/x-msgpack"
]
body = Dict(
:inputs => Dict(
:a => 8
),
:outputs => [:y]
)
r = HTTP.post("http://localhost:1234/v1/notebook/rest_test.jl/eval", headers, MsgPack.pack(body))
@show MsgPack.unpack(r.body) Regarding the headers:
3rd Scenario - From other Pluto notebooksThis currently works if you insert a I really appreciate the feedback as it helps me tremendously in figuring out which parts of the interface and API still need work, so thanks again! |
Beta Was this translation helpful? Give feedback.
-
For illustrating the cross-language capabilities: with the following code you can access the Pluto REST API from Python (based on @ctrekker 's answer for Julia above): import requests
import msgpack
headers = {"Content-Type": "application/x-msgpack", "Accept": "application/x-msgpack"}
body = {"inputs": {'a': 8}, "outputs": ['y']}
r = requests.post(url="http://localhost:1234/v1/notebook/rest_test.jl/eval", headers=headers, data=msgpack.packb(body))
msgpack.unpackb(r.content) |
Beta Was this translation helpful? Give feedback.
I'm so glad you tried it out, this feedback is very helpful for me! I'm glad the first case works as expected, I have a few notes regarding the 2nd and 3rd.
For interacting with a standard HTTP request the requirements are rather specific, which is why I'm currently working on writing some more detailed documentation for the HTTP API itself. I've uploaded the notebook in it's unfinished state here. It currently contains information about how serialization works and the form
eval
requests must take.2nd Scenario - Manual HTTP Requests
For example, the following example will use the HTTP API to update
a
and retrieve the resulting value ofy
.