Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

An example of web #109

Open
jianzs opened this issue Dec 27, 2023 · 0 comments
Open

An example of web #109

jianzs opened this issue Dec 27, 2023 · 0 comments

Comments

@jianzs
Copy link
Contributor

jianzs commented Dec 27, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant