Latest Socket ResearchMalicious Chrome Extension Performs Hidden Affiliate Hijacking.Details
Socket
Book a DemoInstallSign in
Socket

@microfleet/plugin-router

Package Overview
Dependencies
Maintainers
2
Versions
75
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@microfleet/plugin-router

Router for `Microfleet`. Adds ability to call specific functions - `ServiceAction` - using different transports (`amqp`, `http`, `socketio`).

Source
npmnpm
Version
4.0.0
Version published
Weekly downloads
37
-26%
Maintainers
2
Weekly downloads
 
Created
Source

@microfleet/plugin-router

Router for Microfleet. Adds ability to call specific functions - ServiceAction - using different transports (amqp, http, socketio).

Usage

// schemas/add-cat.json
{
  "$id": "create-cat",
  "type": "object",
  "required": ["name"],
  "additionalProperties": false,
  "properties": {
    "name": {
      "type": "string"
    },
    "color": {
      "type": "string",
      "default": "gray"
    }
  }
}
// src/actions/create-cat.ts
import { Microfleet } from '@microfleet/core'
import { ServiceRequest } from '@microfleet/plugin-router'

const cats = []

export default async function createCatAction(this: Microfleet, request: ServiceRequest): Promise<string> {
  const { color, name } = request.params
  const cat = { color, name }

  cats.push(cat)

  return `${name} was created!`
}
// src/index.js
const service = new Microfleet({
  name: 'cats api',
  plugins: [
    'validator',
    'logger',
    'hapi',
    'router',
    'router-hapi',
  ],
})

await service.connect()
$ curl -XPOST "http://0.0.0.0:3000/create-cats" -d '{"name":"perchik","color":"pepper"}' -H "Content-Type: application/json"
Perchik was created!

ServiceAction

Handler for transport request.

Signature

(this: Microfleet, request: ServiceRequest) => Promise<any>

Additional properties

@todo

ServiceRequest

Object with the following structure.

Lifecycle

Extensions

FAQs

Package last updated on 01 Aug 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