RoExpress: Typed Route Example
This page explains the RoExpress route example already available in My Code. It covers the calls used in that example.
Module location
The example expects a RoExpress module at game.ReplicatedStorage.RoExpress. Make sure the module is present in your project before running the example.
Define the server route
In a server script, require the module and get the app. The route below declares a numeric userId parameter and sends that value back in the response.
local RoExpress = require(game.ReplicatedStorage.RoExpress)
local app = RoExpress.GetApp()
app:Get("player/:userId=number", function(req, res)
res:Send({ userId = req.params.userId })
end) Request the route on the client
In a client script, require the module, get the network, and request player/123. The example handles the response with Then and returns its data.
local RoExpress = require(game.ReplicatedStorage.RoExpress)
local network = RoExpress.GetNetwork()
network:GetAsync("player/123"):Then(function(res)
return res.data
end) Calls used in this example
| Call | Role in the example |
|---|---|
RoExpress.GetApp() | Gets the app used to register the server route. |
app:Get(path, handler) | Registers the GET route and its handler. |
req.params.userId | Reads the route parameter. |
res:Send(data) | Sends the response data. |
RoExpress.GetNetwork() | Gets the network used by the client. |
network:GetAsync(path) | Requests the route. |
Then(handler) | Handles the returned response. |
Continue learning
Read the scripting tutorials for more examples of working with scripts and modules.