routes
HTTP API framework similar to flask.
Classes
Request(path='/', method='GET', data=None, params=None)
Bases: object
Request wrapper object.
Source code in pyrevitlib/pyrevit/routes/server/base.py
Attributes
path = path
instance-attribute
method = method
instance-attribute
data = data
instance-attribute
headers
property
Request headers dict.
params
property
Request parameters.
callback_url
property
Request callback url, if provided in payload.
Functions
Response(status=200, data=None, headers=None)
Bases: object
Response wrapper object.
Source code in pyrevitlib/pyrevit/routes/server/base.py
Attributes
status = status
instance-attribute
data = data
instance-attribute
headers
property
Response headers dict.
Functions
API(name)
Bases: object
API root object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str
|
URL-safe unique root name of the API |
required |
Examples:
from pyrevit import routes
api = routes.API("pyrevit-core")
@api.route('/sessions/', methods=['POST'])
def reload_pyrevit(uiapp):
new_session_id = sessionmgr.reload_pyrevit()
return {"session_id": new_session_id}
Source code in pyrevitlib/pyrevit/routes/__init__.py
Attributes
name = name
instance-attribute
Functions
route(pattern, methods=['GET'])
Define a new route on this API.
Source code in pyrevitlib/pyrevit/routes/__init__.py
Functions
init()
Initialize routes. Reset all registered routes and shutdown servers.
activate_server()
Activate routes server for this host instance.
Source code in pyrevitlib/pyrevit/routes/server/__init__.py
deactivate_server()
Deactivate the active routes server for this host instance.
Source code in pyrevitlib/pyrevit/routes/server/__init__.py
get_active_server()
make_response(data, status=OK, headers=None)
Create Reponse object with.
get_routes(api_name)
Get all registered routes for given API name.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
api_name |
str
|
unique name of the api |
required |
add_route(api_name, pattern, method, handler_func)
Add new route for given API name.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
api_name |
str
|
unique name of the api |
required |
pattern |
str
|
route pattern |
required |
method |
str
|
method name |
required |
handler_func |
function
|
route handler function |
required |
Source code in pyrevitlib/pyrevit/routes/server/__init__.py
remove_route(api_name, pattern, method)
Remove previously registered route for given API name.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
api_name |
str
|
unique name of the api |
required |
pattern |
str
|
route pattern |
required |
method |
str
|
method name |
required |