Skip to main content

flash

Flash is a declarative web framework in TypeScript, particularly optimized for building cloud microservices with a REST API on a serverless platforms with Deno.

Warning
Flash is still an alpha version. Do not use it for production use yet, unless you are a contributor to the framework.

Concepts

  • Stay RESTful.
  • You implement, we type.

Features / Roadmap

  • 🚀 Multi Platform
    • Cloudflare Workers
    • Deno Deploy
  • :magic_wand: Progressive APIs
    • Polymorphism in resource implementation
    • Syntax sugar for responses
    • Tree-structured routers
    • Strong type inference
  • 🌤️ Middlewares for Cloudflare Workers
    • Built-in object storage associated with each resource collection
    • Blocking communication among workers
  • 📜 Code/Doc Generation
    • Universal Typescript SDK for clients
    • OpenAPI specs
    • Seamless hosting of API documents
  • ⚙️ Advanced functionalities
    • Multipart support
    • GraphQL server
  • Zero third-party dependencies

Usage

Cloudflare Workers

Create a worker module file:

// index.ts
import { flare } from "https://deno.land/x/flash/mod.ts";

export default flare({ "/": "Welcome to flash!" });

And deploy with Denoflare!

$ denoflare push index.ts --name flash-demo

Examples

APIs

Routers

Implemented with the standard URLPattern interface.

flare({
  "/": "Welcome to flash!",
  "/users/:name": ({ params }) => params.name,
});

Error Handlers

You can define error handlers within a router.

flare({
  "/": "Welcome to flash!",
  404: "Not Found",
  500: "Unexpected Error",
});

Request Handlers

You can access various utility objects provided by Flash in addition to standard arguments of a platform:

flare({
  "/": ({ request, env, context, params, errors, ...}) => ...
});

You can replace a handler with a value if you don’t refer to any argument;

flare({
  "/": () => "Hello",
});

can be rewritten as

flare({
  "/": "Hello",
});

Responses

You can use syntax sugar to create a response with a specified status. You can omit it for a response with the OK status:

flare({
  "/": { 200: "Hello" },
});
flare({
  "/": "Hello",
});

Formatters

You can add different formatters for each response status:

flare({
  // [200] "Hello"
  "/": "Hello",

  // [400] "Not Found",
  404: "Not Found",

  // [500] { message: "Unexpected Error" }
  500: "Unexpected Error",

  format: {
    error: { message: true },
    400: { message: false },
  },
});

Object Storage (Cloudflare Workers)

Built-in object storage associated with each resource collection, implemented with Durable Objects.

flare({
  "/users": {
    GET: async ({ storage }) => {
      return await storage.list();
    },
    POST: async ({ request, storage }) => {
      const body = await request.json();
      await storage.put(body.name, body);
      return { 201: body };
    },
  },
  "/users/:name": {
    GET: async ({ params, storage }) => {
      return await storage.get(params.name);
    },
  },
}

Acknowledgment

Development of Flash is supported by Active Connector Inc..