I got a technical assessment that I've been messing with but can't get working. I need to get this HTML form working. The API call has to be done on the backend using isomorphic-fetch, their rules. What needs to happen to meet MVP I guess is that form needs to send the backend the search term, the backend needs to call the dog API for a photo of the dog from the search term, and that data needs to be sent back to the front, and then displayed. Seems easy but I'm struggling to get it working. Any help would be appreciated, thank you. Even just some help getting these params passed from front to back would be awesome. I've used express but not koa, and that was over a year ago.
Here is the code.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/water.css@2/out/water.css">
<title>Lots of dogs! </title>
</head>
<body>
<h1>Lots of dogs! </h1>
<p>See photos of your favorite dogs</p>
<form>
<input type="text" name="breed" placeholder="Enter a dog breed">
<button type="submit">Fetch</button>
</form>
</body>
</html>
import Koa from "koa";
import Router from "@koa/router";
import cors from "@koa/cors";
import fetch from "isomorphic-fetch";
const app = new Koa();
const router = new Router();
const port = 3011;
app.use(cors({ origin: "*" }));
router.get("/", (ctx) => {
ctx.body = "hello!";
});
app.use(async (ctx, next) => {
await next();
const rt = ctx.response.get("X-Response-Time");
console.log(`${ctx.method} ${ctx.url} - ${rt}`);
});
app.use(async (ctx, next) => {
const start = Date.now();
await next();
const ms = Date.now() - start;
ctx.set("X-Response-Time", `${ms}ms`);
});
router.get("/:searchTerm", async (ctx, next) => {
const breed = req.params;
console.log(`breed: ${breed}`);
});
const fetchBreedImage = () => {
fetch("https://dog.ceo/api/breed/hound/images").then((data) =>
console.log(data)
);
};
app.use(router.routes());
app.listen(port, () => {
console.log(`Server running on http://localhost:${port}`);
});