3.1.3 • Published 3 months ago

@microfleet/plugin-router v3.1.3

Weekly downloads
-
License
MIT
Repository
github
Last release
3 months ago

@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

3.1.3

3 months ago

3.1.2

3 months ago

3.1.1

3 months ago

3.1.0

3 months ago

3.0.5

4 months ago

3.0.4

4 months ago

3.0.3

4 months ago

3.0.2

4 months ago

3.0.1

4 months ago

3.0.0

4 months ago

2.3.0

4 months ago

2.2.14

5 months ago

2.2.13

5 months ago

2.2.11

6 months ago

2.2.12

5 months ago

2.2.10

6 months ago

2.2.9

7 months ago

2.2.2

12 months ago

2.2.5

12 months ago

2.2.4

12 months ago

2.2.7

11 months ago

2.2.6

12 months ago

2.2.8

11 months ago

2.2.0

1 year ago

2.0.0

1 year ago

0.25.0

2 years ago

0.23.0

2 years ago

0.21.0

2 years ago

0.21.2

2 years ago

0.19.0

2 years ago

0.19.2

2 years ago

0.15.0

2 years ago

0.17.0

2 years ago

0.11.0

2 years ago

0.13.0

2 years ago

0.11.2

2 years ago

0.9.0

2 years ago

0.7.2

2 years ago

0.7.4

2 years ago

0.5.0

2 years ago

0.7.0

2 years ago

0.5.2

2 years ago

0.3.14

2 years ago

0.3.12

2 years ago

0.3.10

2 years ago

0.3.0

2 years ago

0.3.6

2 years ago

0.3.8

2 years ago

0.3.2

2 years ago

0.3.4

2 years ago

0.0.0-dev.11

2 years ago

0.0.0-dev.9

2 years ago

0.0.0-dev.10

2 years ago

0.0.0-dev.8

2 years ago

0.0.0-dev.7

2 years ago

0.0.0-dev.5

3 years ago

0.0.0-dev.4

3 years ago

0.0.0-dev.3

3 years ago

0.0.0-dev.6

3 years ago

0.0.0-dev.2

3 years ago

0.0.0-dev.1

3 years ago

0.0.0-next.590

3 years ago

0.0.0-next.589

3 years ago

0.0.0-next.582

3 years ago

0.0.0-next.580

3 years ago

0.0.0-next.577

3 years ago

0.0.0-next.570

3 years ago

0.0.0-next.566

3 years ago

0.0.0-next.562

3 years ago