Socket
Socket
Sign inDemoInstall

18h

Package Overview
Dependencies
Maintainers
1
Versions
44
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

18h

A Next.js style dynamic API router for Koa-based APIs.


Version published
Weekly downloads
140
increased by16.67%
Maintainers
1
Weekly downloads
 
Created
Source

18h

18h is a wrapper for Koa which allows you to create Next.js-style, serverful dynamic API routing sourced from a directory of your choosing.

Installation

npm i 18h

Usage

/** /src/index.ts */

createRouter({
  routesFolder: join(__dirname, "routes"),
  port: 4000,
});
/** /src/routes/users/[userId]/delete.ts */

import { Route } from "18h";
import { deleteUserById } from "@/actions/users";
import { postRequestCleanupAction } from "@/example/ambiguous";

const handler: Route<{}, { success: boolean }, { userId: string }> = {
  async handler(context) {
    const success = await deleteUserById(context.params.userId);

    return {
      headers: {
        "X-Custom-Header": "true",
      },
      body: { success },
      code: success ? 200 : 500,
    };
  },
  middleware: {
    post: [postRequestCleanupAction],
  },
};

export default handler;

Example Consumption Based on Example Above

import axios from "axios";

(async () => {
  const success = await axios
    .post("http://localhost:4000/users/123/delete")
    .then(({ data }) => data.success);

  console.log(success); // true;
})();

More details & documentation coming soon! 👊

Keywords

FAQs

Package last updated on 10 May 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc