Open jianzs opened 11 months ago
After #120, this feature becomes available on the cloud platform. However, it's not yet supported in the simulation environment. A redesign of simulator is necessary to accommodate for simulation needs.
This is an example that leverages this feature, identical to the app-with-prop-access
located in the testapps
.
import { Router, Tester, HttpRequest, HttpResponse } from "@plutolang/pluto";
const router = new Router("router");
router.get("/echo", async (req: HttpRequest): Promise<HttpResponse> => {
const message = req.query["message"] ?? "Hello, Pluto!";
return {
statusCode: 200,
body: message,
};
});
const tester = new Tester("e2e");
tester.it("test echo", async () => {
// Verify the correctness of business logic.
const res = await fetch(router.url + "/echo?message=Hello%20Pluto!");
const body = await res.text();
if (res.status !== 200) {
throw new Error(`Unexpected status code: ${res.status}`);
}
if (body !== "Hello Pluto!") {
throw new Error(`Unexpected body: ${body}`);
}
});
https://github.com/pluto-lang/pluto/blob/main/docs/documentation/design/capture-value.en.md