Skip to content

Commit

Permalink
Unified REST interface
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr committed Mar 30, 2020
1 parent 789f6e2 commit 90c26e0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
4 changes: 3 additions & 1 deletion panel/command/serve.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from tornado.wsgi import WSGIContainer
from tornado.web import FallbackHandler

from ..io.rest import ParamHandler, build_tranquilize_application
from ..io.server import INDEX_HTML
from ..util import bokeh_version

Expand Down Expand Up @@ -49,10 +50,11 @@ def customize_kwargs(self, args, server_kwargs):
# Handle tranquilized functions in the supplied functions
kwargs['extra_patterns'] = patterns = []
if args.rest_provider == 'tranquilizer':
from ..io.rest import build_tranquilize_application
app = build_tranquilize_application(files, args)
tr = WSGIContainer(app)
patterns.append((r"^/%s/.*" % args.rest_endpoint, FallbackHandler, dict(fallback=tr)))
elif arg.rest_provider == 'param':
extra_patterns.append((r"^/rest/.*", ParamHandler))
elif args.rest_provider is not None:
raise ValueError("rest-provider %r not recognized." % args.rest_provider)
return server_kwargs
Expand Down
8 changes: 8 additions & 0 deletions panel/io/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ class _state(param.Parameterized):
# Stores a set of locked Websockets, reset after every change event
_locks = WeakSet()

# Endpoints
_rest_endpoints = {}

def __repr__(self):
server_info = []
for server, panel, docs in self._servers.values():
Expand All @@ -78,6 +81,11 @@ def _unblocked(self, doc):
thread_id = thread.ident if thread else None
return (doc is self.curdoc and self._thread_id == thread_id)

def publish(self, endpoint, parameterized, input=None, output=None):
if output is None:
output = list(parameterized.param)
self._rest_endpoints[(self.curdoc, endpoint)] = (parameterized, input, output)

@property
def curdoc(self):
if self._curdoc:
Expand Down

0 comments on commit 90c26e0

Please sign in to comment.