Get started with Services#
Using the omni.services
extensions and Omniverse Kit’s --exec
command-line option makes it easy to get started with services.
As the service evolves and grows, it might be worth turning the service itself into an Extension so that it is easy to ship and distribute.
Doing so will also give all the power of extensions to services, with the possibilities to set up dependencies on other extensions, install additional Python packages and take advantage of the settings framework.
Create a Basic service#
Starting with a very simple “Hello World” Python example:
1from omni.services.core import main
2
3def hello_world():
4 return "Hello World!"
5
6main.register_endpoint("get", "/hello-world", hello_world)
That is all there is needed to write a service. To run this with Omniverse Kit and an HTTP transport:
./kit --exec hello_world.py --enable omni.services.core --enable omni.services.transport.server.http
By default, an API documentation page is created to list the services exposed, and accessible at http://localhost:8011/docs
It is possible to exercise the API from that webpage by using the Try it out
feature within the different endpoints.
Create an Advanced service#
Please find a more advanced example of a service in this GitHub Repository
Omniverse Kit ships with several more advanced services and more are available in the extension registry. Omniverse Farm is also fully built using the microservices stack within Omniverse and is made up several different services. It’s code is available from the Omniverse Launcher where you can explore the code.