4.0.1 • Published 11 months ago

@microfleet/plugin-router v4.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
11 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

4.0.1

11 months ago

4.0.0

11 months ago

3.1.4

12 months ago

3.1.3

1 year ago

3.1.2

1 year ago

3.1.1

1 year ago

3.1.0

1 year ago

3.0.5

1 year ago

3.0.4

1 year ago

3.0.3

1 year ago

3.0.2

1 year ago

3.0.1

1 year ago

3.0.0

1 year ago

2.3.0

1 year ago

2.2.14

1 year ago

2.2.13

1 year ago

2.2.11

2 years ago

2.2.12

2 years ago

2.2.10

2 years ago

2.2.9

2 years ago

2.2.2

2 years ago

2.2.5

2 years ago

2.2.4

2 years ago

2.2.7

2 years ago

2.2.6

2 years ago

2.2.8

2 years ago

2.2.0

2 years ago

2.0.0

2 years ago

0.25.0

3 years ago

0.23.0

3 years ago

0.21.0

3 years ago

0.21.2

3 years ago

0.19.0

3 years ago

0.19.2

3 years ago

0.15.0

3 years ago

0.17.0

3 years ago

0.11.0

3 years ago

0.13.0

3 years ago

0.11.2

3 years ago

0.9.0

3 years ago

0.7.2

3 years ago

0.7.4

3 years ago

0.5.0

3 years ago

0.7.0

3 years ago

0.5.2

3 years ago

0.3.14

3 years ago

0.3.12

3 years ago

0.3.10

3 years ago

0.3.0

3 years ago

0.3.6

3 years ago

0.3.8

3 years ago

0.3.2

3 years ago

0.3.4

3 years ago

0.0.0-dev.11

3 years ago

0.0.0-dev.9

4 years ago

0.0.0-dev.10

4 years ago

0.0.0-dev.8

4 years ago

0.0.0-dev.7

4 years ago

0.0.0-dev.5

4 years ago

0.0.0-dev.4

4 years ago

0.0.0-dev.3

4 years ago

0.0.0-dev.6

4 years ago

0.0.0-dev.2

4 years ago

0.0.0-dev.1

4 years ago

0.0.0-next.590

4 years ago

0.0.0-next.589

4 years ago

0.0.0-next.582

4 years ago

0.0.0-next.580

4 years ago

0.0.0-next.577

4 years ago

0.0.0-next.570

4 years ago

0.0.0-next.566

4 years ago

0.0.0-next.562

4 years ago