Bring your mojo Api to your network with a simple FireTCP server!!
- mojo version 24.4.0 or newer
- Python version 3.10 or newer
Step 1: $ mkdir hello_fire_api && cd hello_fire_api
Step 2: $ curl -sS https://raw.githubusercontent.com/Jensen-holm/FireTCP/main/install.sh | bash
Step 3: Once you have made a project and cloned the FireApi you can get coding! Check out the examples below or in the examples directory before getting started or read this tutorial I made on medium.
app.mojo
from FireTCP import TCP
@value
struct HelloService(TCP.Service):
fn func(self, req: TCP.Request) raises -> TCP.Response:
return TCP.Response(
body="You sent the following data: " + req.body(),
)
fn main() raises -> None:
var server = TCP.TCPLite[HelloService](
service=HelloService(),
port=9090,
host_addr="127.0.0.1",
)
server.serve()
client.mojo
from FireTCP import TCP
fn main() raises -> None:
var client = TCP.Client(
port=9090,
host_name="127.0.0.1",
)
var request = TCP.Request(
body="Hello FireTCP",
)
var response = client.send_request(request)
print(response.body())
output: "You sent the following data: Hello FireTCP"