npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

funclify

v0.2.0

Published

Funclify is an **opinionated** framework for building APIs on Netlify Functions. It's fast, it's powerful and most importantly focused around a great developer experience.

Downloads

5

Readme

Funclify 🤖

Funclify is an opinionated framework for building APIs on Netlify Functions. It's fast, it's powerful and most importantly focused around a great developer experience.

Currently, this is a TypeScript-only framework. This reflects the current focus of the project, being a type-safe and DX focused package, and in the future it may be updated to compile to support ESM. It's early days, so please forgive the narrow-focus.

⚠️ Just one thing!

Funclify is very early on in it's development. It may be abandoned, it may be completely up-ended and rewriten in Rust 👀, so as much as I'd love to say use this in production, bear those things in mind.

Install

# pnpm
pnpm add funclify

# npm
npm install funclify

Basic Use

Funclify includes an API class which is the entry point for both defining handlers and also processing requests.

// netlify/functions/api.ts
import { Api } from 'funclify';

const api = new Api();

api.get("/", async (_, res) => {
    return res.withJSON({ message: "Hello World!" });
});

export const handler = api.baseHandler;

Typed Route Parameters

Funclify is focused on being a strongly-typed framework. This extends to route parameters. Making heavy use of infer, we can create a strongly-typed params property that lives on the req argument passed to your route handler.

api.get("/users/:user_id/orders/:order_id", async({ params }, res) => {
    // params: { user_id: string, order_id: string }
    const { user_id, order_id } = params;

    const order = await fetchOrder(user_id, order_id);

    return res.withJSON(order);
})

Testing

Funclify comes bundled with a test harness to make it simple to run integration tests against your API.

Although you could adopt a more "unit" approach, the framework is built to encourage testing to the boundary of your application for each and every API route.

An example below utilising Vitest

import { describe, it, beforeEach, expect } from "vitest";
import { ApiTestHarness } from "funclify";
import { api } from "../functions/api";

describe("API", () => {
  let test: ApiTestHarness<typeof api>;

  beforeEach(() => {
    // This could be set once rather than in before-each, as
    // in theory an API should be idempotent. However, for flexibility
    // atomicity can be guaranteed by initialising in the beforeEach
    test = new ApiTestHarness(api);
  });

  it("should return a user object", async () => {
    // Perform the request. Under the hood, this
    // emulates the `event` and `context` fed in
    // from a Netlify Function
    const response = await test.get("/user/123");

    expect(response.statusCode).toBe(200);

    // Regardless of your application output, the response
    // from a Netlify Function will be a string, so we need
    // to parse into JSON to assert on the returned objects
    expect(response.body).toBeTypeOf("string");

    const body = JSON.parse(response.body!);
    expect(body).toContain({
      id: "123",
      name: "Ed",
    });
  });
});