Skip to content

Instantly share code, notes, and snippets.

@ctrekker
Created June 30, 2021 16:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ctrekker/32bed71928927cf9dfb87c2368eaf487 to your computer and use it in GitHub Desktop.
Save ctrekker/32bed71928927cf9dfb87c2368eaf487 to your computer and use it in GitHub Desktop.
### A Pluto.jl notebook ###
# v0.14.3
using Markdown
using InteractiveUtils
# ╔═╡ 732b9e4a-7852-45f3-8dfb-4840570f1006
html"""
<style>
.requestBody, .responseBody {
font-size: 0.7em;
}
</style>
"""
# ╔═╡ acaab1c0-ae95-11eb-2113-ed072f61171b
md"""
# What you see is what you rest — HTTP Docs
This documentation is for users that wish to interact *directly* to the Pluto WYSIWYR HTTP interface *without* the use of a client library. It is recommended that you use a client library if possible.
### List of client libraries
As of now the following client libraries are available:
* [Julia](REST Docs.jl) (built into Pluto)
* [Node.js](https://github.com/ctrekker/pluto-rest)
* [Python](https://github.com/ctrekker/pyplutorest)
"""
# ╔═╡ 3353b1c1-911b-4b5a-8d26-32091b305a3d
md"""
## Serialization
To uphold interlanguage compatibility multiple serialization methods are supported. Native [Julia serialization](https://docs.julialang.org/en/v1/stdlib/Serialization/) is used for Julia → Julia communication via the Julia client library. For other clients which cannot serialize objects through Julia though, MsgPack is provided as an alternative serialization method.
Internally Pluto uses MsgPack with several extensions for all communication between the editor and the backend. These extensions provide functionality for serializing and deserializing arrays of a specific numeric precision. For example, native MsgPack does not support serializing Int16 (short) types without first converting them to a full integer type. The Pluto extensions address this issue with several MsgPack extensions, all of which should be implemented for a custom client library.
Refer to the [MsgPack.jl](https://github.com/fonsp/Pluto.jl/blob/main/src/webserver/MsgPack.jl) or [MsgPack.js](https://github.com/fonsp/Pluto.jl/blob/main/frontend/common/MsgPack.js) files from the Pluto source code for examples in Julia or JavaScript respectively.
### Headers
Serialization method is determined from client provided headers. The first, `Content-Type`, specifies what serialization method will be used for the request body. This tells Pluto how to *deserialize* the body. The next header, `Accept`, tells Pluto how to *serialize* the response.
**For MsgPack:**
```
Content-Type: application/x-msgpack
Accept: application/x-msgpack
```
**For Julia Serialization:**
```
Content-Type: application/x-julia
Accept: application/x-julia
```
"""
# ╔═╡ 7ff29b2c-1fef-4c2f-9ce6-2ce35c720c9d
html"""
<h2>Evaluation</h2>
<h3>URL Format</h3>
<pre>
POST http://&lt;PLUTO_HOST&gt;/v1/notebook/&lt;FILENAME&gt;/eval
</pre>
<div><b>PLUTO_HOST</b>: Base URL of Pluto server. Defaults to `localhost:1234` in Pluto as well as within each client library</div>
<div><b>FILENAME</b>: URL-encoded file name of the notebook to evaluate within.</div>
<h3>Request Body</h3>
<pre class="requestBody">
{
"inputs": {
"&lt;in_variable_1&gt;": &lt;value_1&gt;,
"&lt;in_variable_2&gt;": &lt;value_2&gt;,
⋮ ⋮
"&lt;in_variable_n&gt;": &lt;value_n&gt;
},
"outputs": [
"&lt;out_variable&gt;"
]
}
</pre>
<b>NOTE</b>: Currently requesting only a single output is possible, but requesting multiple is likely to be implemented in the future
<h4>Example</h4>
<pre class="requestBody">
{
"inputs": {
"a": 3,
"b": 4
},
"outputs": [ "c" ]
}
</pre>
<h3>Response Body</h3>
<pre class="responseBody">
{
"&lt;out_variable&gt;": &lt;out_value&gt;
}
</pre>
<h4>Example</h4>
<pre class="responseBody">
{
"c": 5
}
</pre>
"""
# ╔═╡ Cell order:
# ╟─732b9e4a-7852-45f3-8dfb-4840570f1006
# ╟─acaab1c0-ae95-11eb-2113-ed072f61171b
# ╟─3353b1c1-911b-4b5a-8d26-32091b305a3d
# ╟─7ff29b2c-1fef-4c2f-9ce6-2ce35c720c9d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment