pluto
pluto copied to clipboard
An example of web
import { Router, HttpRequest, HttpResponse } from "@plutolang/pluto";
var users = [
{ name: 'tobi' },
{ name: 'loki' },
{ name: 'jane' }
];
const router = new Router("router");
router.get("/api/users", async (req: HttpRequest): Promise<HttpResponse> => {
return { statusCode: 200, body: JSON.stringify(users) };
});
router.post("/api/user/:name", async (req: HttpRequest): Promise<HttpResponse> => {
const newUser = req.params.name;
users.push({ name: newUser });
return { statusCode: 200 };
});
// Can be used to display the URL of the HTTP server.
console.log(`The URL of the HTTP server is`, router.url);
const routerTester = new Tester("router tester");
routerTester.it("test case", async () => {
// Can be used to perform end-to-end testing for the HTTP server.
const resp = await fetch(router.url);
if (resp.status !== 200) {
throw new Error("failed.");
}
});
Expected Behavior
During the testing phase, deduce and generate 3 lambda functions corresponding to two handlers of the Router and the test case of the Tester. After deployment, invoke the lambda corresponding to the Tester's test case for execution.
In the deployment phase, also deduce and generate 3 lambda functions corresponding to the two handlers of the Router and the main code. After deployment, invoke the lambda corresponding to the main code for execution.