[go: up one dir, main page]

Skip to content

predetermined/aqua

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Aqua

Aqua is a minimal and fast web framework.

⚠️ This version is a WIP and has not yet been released. Please refer to the main branch for the current documentation.

Example usage

It starts easy,

import { Aqua } from "...";

const app = new Aqua({
  listen: {
    port: 80,
  },
});

app
  .route("/")
  .on(Method.GET)
  .respond((_event) => {
    return new Response("Hello, World!");
  });

... and stays easy.

const v1 = app.route("/v1").step(async (event) => {
  if (!event.request.headers.has("X-Api-Key")) {
    throw new ResponseError(
      "Missing API key",
      Response.json({ error: "MISSING_API_KEY" })
    );
  }

  const user = await getUserByRequest(event.request);
  //    ^ type User

  return {
    ...event,
    user,
  };
});

v1.route("/user")
  .on(Method.GET)
  .respond((event) => Response.json({ data: { user: event.user } }));
//                                                        ^ type User