Python
- Setup your app folder
mkdir reboot-hello && cd reboot-hello
- Install Reboot
python3 -m venv ./.venv && source .venv/bin/activate && pip install reboot
- Create a
.proto
filemkdir -p ./api/hello/v1 && touch ./api/hello/v1/hello.proto
- Define your durable state data types and operations
syntax = "proto3";
package hello.v1;
import "rbt/v1alpha1/options.proto";
message Hello {
option (rbt.v1alpha1.state) = {};
repeated string messages = 1;
}
service HelloMethods {
rpc Messages(MessagesRequest) returns (MessagesResponse) {
option (rbt.v1alpha1.method).reader = {};
}
rpc Send(SendRequest) returns (SendResponse) {
option (rbt.v1alpha1.method).writer = {};
}
}
message MessagesRequest {}
message MessagesResponse {
repeated string messages = 1;
}
message SendRequest {
string message = 1;
}
message SendResponse {} - Create
.py
implementation filemkdir -p ./backend/src && touch ./backend/src/hello_servicer.py
- Implement
HelloServicer
from hello.v1.hello_rbt import (
Hello,
MessagesRequest,
MessagesResponse,
SendRequest,
SendResponse,
)
from rebootdev.aio.contexts import ReaderContext, WriterContext
class HelloServicer(Hello.Servicer):
async def Messages(
self,
context: ReaderContext,
request: MessagesRequest,
) -> MessagesResponse:
return MessagesResponse(messages=self.state.messages)
async def Send(
self,
context: WriterContext,
request: SendRequest,
) -> SendResponse:
self.state.messages.append(request.message)
return SendResponse() - Create a
main
entrypointtouch ./backend/src/main.py
- Implement
main.py
import asyncio
from hello.v1.hello_rbt import Hello
from hello_servicer import HelloServicer
from reboot.aio.applications import Application
from rebootdev.aio.external import InitializeContext
async def initialize(context: InitializeContext):
hello = Hello.ref('reboot-hello')
await hello.Send(
context,
message='Hello, World!',
)
async def main():
application = Application(
servicers=[HelloServicer],
initialize=initialize,
)
await application.run()
if __name__ == '__main__':
asyncio.run(main()) - Create an
.rbtrc
filetouch .rbtrc
- Add necessary flags to your
.rbtrc
filegenerate api/
generate --python=backend/api/
dev run --name=hello
dev run --watch=backend/src/**/*.py
dev run --python
dev run --application=backend/src/main.py - Run your app
rbt dev run
- Query your app
curl -XPOST http://localhost:9991/hello.v1.HelloMethods/Messages \
-H "x-reboot-state-ref:hello.v1.Hello:reboot-hello"
Next steps
Well done! You made it!
This example is somewhat contrived as we only created one instance of
your Hello
data type, but in practice you are free to make as many
of these as you like!
Check out these links to continue your exploration:
- Build a React frontend - create a React frontend that connects to your backend and displays your messages in real-time.
- Learn about transactions - so far,
we've covered
reader
andwriter
methods, but Reboot's power extends totransactions
. Learn abouttransactions
and all of the other method kinds here. - Join us on Discord - to ask questions and let us know what you think!
Hopefully, your wheels are starting to spin thinking of all of the possibilities!