-
Houdini’s embedded web server is a multi-threaded HTTP server written in C++ that can call Python functions (or C++ extensions) to handle web requests.
-
Its primary intended use is to build service-oriented APIs to access Houdini scene data.
-
There is only one global embedded web server for each running instance of Houdini.
-
You can specify path handlers using the hou.webServer.urlHandler() decorator, or build an API using the hou.webServer.apiFunction() decorator.
-
Then, you can start the embedded server using hou.webServer.run():
hou.webServer.run(8008, debug=True)
Note
If you call this function from a non-graphical session, it will not return (unless the server is interrupted or server code calls hou.webServer.requestShutdown()).
-
To try out the server from the command line:
-
Put the following code in a
server.py
file:server.py
import hou @hou.webServer.urlHandler("/") def my_handler(request): return hou.webServer.Response( "Hello from Houdini %s" % hou.applicationVersionString()) if __name__ == "__main__": hou.webServer.run(8008, debug=True)
-
In a shell with the Houdini environment set up, run
hython server.py
. -
Point a browser to
http://127.0.0.1:8008/
to see the output. -
Stop the server by pressing ⌃ Ctrl + C (Linux and Mac) or ⌃ Ctrl + Break/⌃ Ctrl + ScrLk on Windows.
-
Subtopics ¶
Classes ¶
-
A request made to Houdini’s web server.
-
A response made back from Houdini’s web server.
-
A file uploaded in a request made to Houdini’s web server.
Starting and Stopping ¶
-
Starts Houdini’s web server.
-
hou.webServer.requestShutdown()
Tells Houdini’s web server to shut down after serving all open requests.
-
Returns True if Houdini’s web server was started in debug mode debug=True in )
Handling Web Requests and Returning Responses ¶
-
Decorator for functions that handle requests to Houdini’s web server.
-
Generates a Response object representing an HTTP error.
-
hou.webServer.notFoundResponse()
Generates a Response object representing a 404 Not Found HTTP error.
-
Generates a Response object that sends the contents of a file.
-
Generates a Response object representing a 301 Moved or 302 Found HTTP response.
-
hou.webServer.registerStaticFilesDirectory()
Tells Houdini’s web server to check the given directory for files to automatically serve for URLs that match the given path prefix.
-
hou.webServer.registerOpdefPath()
Tells Houdini’s web server to use the specified prefix as a handler to serve opdef requests.
API Calls ¶
-
Decorator for functions that can be called through an API endpoint on Houdini’s web server, returning JSON or binary responses.
-
Raise this exception in apiFunction handlers to indicate an error.