Socket
Book a DemoInstallSign in
Socket

tinie2

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install
Package was removed
Sorry, it seems this package was removed from the registry

tinie2

tinie: 🪄 Tiny framework that simply converts JavaScript functions into Restful APIs

0.0.1
unpublished
latest
Source
npmnpm
Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

Tinie 🪄

Tinie is tiny framework that simply converts JavaScript functions into Restful APIs inspired by Tanmoy741127/lumi

Feature

  • Create Restful API route from javascript functions
  • Validate parameter with type or types
  • Tinie server wrtten with Fastify

How to start 🚀

  • Install tinie from npm
 $ npm install tinie
  • Write functions and join function into Tinie
import Tinie from "tinie";

const calculator = (
  operation: "add" | "subtract" | "multiply" | "divide" = "divide", // if you set default value on parameter, it's optional
  a: number,
  b: number
) => {
  switch (operation) {
    case "add":
      return a + b;
    case "subtract":
      return a - b;
    case "multiply":
      return a * b;
    case "divide":
      return a / b;
  }
}

const calculatorParamTypes = {
  operation: ["string"], // if you set array on value, it's meant "or"
  a: "number",
  b: "number"
}

const tinie = new Tinie()

tinie.register(calculator, {
  // route: 'calc', // you can set custom routing like this
  types: calculatorParamTypes
})

tinie.listen()
  • Done, Let's check!
 $ curl -X POST -H "Content-Type: application/json" -d '{"operation": "add", "a": 4, "b": 2}' http://127.0.0.1:3000/calculator

TODO

  • 1-Dimensional parameter parsing
  • Multi-Dimensional parameter parsing
  • Advanced type checker

Keywords

tinie

FAQs

Package last updated on 04 Dec 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

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.