HostHttpServer¶
-
class
stencila.
HostHttpServer
(host, address='127.0.0.1', port=2000)[source]¶ A HTTP server for a Host
Provides access to a
Host
via a REST-like HTTP protocol usingPOST
to create new instance andPUT
to run one of it’s methods. Implements authorization using single-, or multi-, use “tickets” and session tokens.The following example illustrates creating a
PythonContext
and then running it’sexecute
method. It uses thehttp
command line tool (https://httpie.org/) for brevity and session management but you could also usecurl
or other HTTP client.# Start the server > python -m stencila Host has started at: http://127.0.0.1:2000/?ticket=w8Z0ZkuWlz8Y Use Ctrl+C to stop # Then in another shell create a new PythonContext (using the above ticket # to obtain access authorization and a session token) using POST > http --session=/tmp/session.json POST :2000/PythonContext?ticket=w8Z0ZkuWlz8Y HTTP/1.0 200 OK Content-Length: 21 Content-Type: application/json Date: Wed, 28 Feb 2018 21:36:37 GMT Server: Werkzeug/0.12.2 Python/2.7.12 Set-Cookie: token=PjvskQ38vtuJQg2hNYEHwPppvw8RKbs0AaYcA9uStannZkGfRr3I0g9jyeQD3L3f; Path=/ "pythonContext1" # Then use the returned name of the PythonContext instance to run it's "execute" method # using PUT > http --session=/tmp/session.json PUT :2000/pythonContext1!execute code='sys.version' HTTP/1.0 200 OK Content-Length: 153 Content-Type: application/json Date: Wed, 28 Feb 2018 21:39:54 GMT Server: Werkzeug/0.12.2 Python/2.7.12 { "messages": [], "value": { "data": "2.7.12 (default, Nov 20 2017, 18:23:56) [GCC 5.4.0 20160609]", "type": "string" } }
-
url
¶ Get the URL of the server
Returns: A URL string
-