This directory contains the example source code for the tutorial Designing RESTful Services in Lua. The example implements a small in-memory user API on top of a reusable Lua router module.
www/.lua/rest.lua- Reusable REST-style router module. See also REST-API.md.www/.preload- Example application that mounts the router under/apiand defines the user endpoints.TestApi.py- Simple client script that exercises the example API.
Start the example with the Mako Server:
cd REST
mako -l::wwwTo test the API with the included Python script, make sure the server is reachable on port 80. On Linux, one way is:
sudo mako -u "$(whoami)" -l::www
python TestApi.pyThe router module in www/.lua/rest.lua lets you register exact and wildcard routes by HTTP method, then installs those routes into the BAS virtual file system as a directory function.
The example app in www/.preload mounts the router under /api and defines these endpoints:
GET /api/usersPOST /api/usersGET /api/users/{id}PUT /api/users/{id}DELETE /api/users/{id}
The example keeps the user records in memory, validates the submitted JSON, and returns JSON responses with appropriate HTTP status codes. TestApi.py then creates, queries, updates, and deletes users against that API.
This example can be packaged as an Xedge app by creating a ZIP from the app directory, so the app files are at the ZIP root. See Xedge App Deployment for the detailed deployment workflow.
cd www
zip -D -q -u -r -9 ../REST.zip .Upload the generated ZIP with the Xedge App Upload tool.
- The example uses in-memory storage only. Restarting the app resets the user list.
- The Python test script assumes
http://localhost/api/users, so make sure the server is listening on the port the script expects.