<aside> <img src="https://s3-us-west-2.amazonaws.com/secure.notion-static.com/997200e9-2347-40cf-87d7-4f41edbbc420/alert.png" alt="https://s3-us-west-2.amazonaws.com/secure.notion-static.com/997200e9-2347-40cf-87d7-4f41edbbc420/alert.png" width="40px" /> pyRevit Routes is a DRAFT and is subject to change There is no authentication mechanism implemented yet

</aside>

<aside> <img src="https://s3-us-west-2.amazonaws.com/secure.notion-static.com/997200e9-2347-40cf-87d7-4f41edbbc420/alert.png" alt="https://s3-us-west-2.amazonaws.com/secure.notion-static.com/997200e9-2347-40cf-87d7-4f41edbbc420/alert.png" width="40px" /> pyRevit Routes is a fairly isolated module under pyrevitlib/pyrevit/routes/ in pyRevit source. You are encouraged to dive into the code and contribute to the project without affecting the other parts of the pyRevit ecosystem

</aside>

What is pyRevit Routes

Let's say we want to create a web application that would display a list of doors in a model. The web application would be split into two parts.

While you are free to select whatever toolchain and GUI framework (React, Vue.js, etc) you are comfortable with for the front-end, the challenge has always been on how to create a back-end that has access to Revit contexts and can query or modify Revit documents. What we really needed is to run a HTTP web server over a running Revit instance and manage the HTTP calls in a way that would be executed in Revit context.

The new Routes python module, is an HTTP micro-framework to create web APIs running over Revit instances. This means that you can create functionality that could be triggerd from remote. This framework provides the necessary mechanism to create a back-end that has access to Revit context.

<aside> <img src="https://s3-us-west-2.amazonaws.com/secure.notion-static.com/01f9b8a6-3c36-442b-bed3-ec193007d66f/ic_01_idea.png" alt="https://s3-us-west-2.amazonaws.com/secure.notion-static.com/01f9b8a6-3c36-442b-bed3-ec193007d66f/ic_01_idea.png" width="40px" /> Fun fact: The Runtime REST API is implemented using this framework

</aside>

Getting Started

Let's create a simple API using the routes module. One important note here is that it is better to place this API inside your extensions' startup script (startup.py) so it only runs once per Revit instance.

Creating Custom HTTP API Extension

Let's create an empty extension that will define our new HTTP API:

MyExtensions/
    └── MyHTTPAPI.extension/
        └── startup.py

Note that the extension does not include anything else other than the startup.py script.

Now let's open the startup.py and import the routes module. This module provides the functionality we need to define the API:

# first import the routes module
from pyrevit import routes