Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@sumor/api-middleware

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@sumor/api-middleware

API Middleware is a middleware for Node.JS. It can easily expose function to api, and validate parameters

  • 1.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
64K
decreased by-2.2%
Maintainers
1
Weekly downloads
 
Created
Source

api-middleware

A Sumor Cloud Tool.
More Documentation API Middleware is a middleware for Node.JS. It can easily expose function to api, and validate parameters

CI Test Coverage Audit

Installation

npm i @sumor/api-middleware --save

Prerequisites

Node.JS version

Require Node.JS version 16.x or above

require Node.JS ES module

As this package is written in ES module, please change the following code in your package.json file:

{
  "type": "module"
}

Usage

Basic Usage

  1. Add a file named plus.js in your project folder api
export default async (context, req, res) => {
  const { data } = context
  const { a, b } = data
  return a + b
}

[Optional] 2. Add a file named plus.json in your project folder api

{
  "name": "plus",
  "parameters": {
    "a": {
      "name": "parameter a",
      "type": "number",
      "length": 3
    },
    "b": {
      "name": "parameter b",
      "type": "number"
    }
  }
}
  1. Add the following code in your index.js file
import express from 'express'
import apiMiddleware from '@sumor/api-middleware'

const app = express()
apiMiddleware(app, process.cwd() + '/api')

app.listen(3000, () => {
  console.log('Server is running on http://localhost:3000')
})
  1. run index.js

    node index.js
    

Keywords

FAQs

Package last updated on 17 May 2024

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