# Action

# Scaffold a new action

yarn ilos generate Handler Hello
1

Now you've a file in src/actions/HelloAction.ts;

# Handler name

@Container.handler({
  service: 'myService',
  method: 'Hello',
})
1
2
3
4

Here you can configure your handler service name, method name and even version (default is 'latest')

# Handler dependencies

export class HelloAction extends Parents.Action {
  constructor(
    // here inject your dependencies
    // private provider: MyProviderInterfaceResolver,
  ) {
    super();
  }
}
1
2
3
4
5
6
7
8

In the constructor your can add your dependencies using Ilos IOC. By example, you may add your database repository provider to access data from db. Note: you may inject interface and bind implementation later in the service provider and not the final class directly

# Handler implementation

 protected async handle(
    params: Types.ParamsType,
    context: Types.ContextType,
  ): Promise<Types.ResultType> {
    // 
  }
1
2
3
4
5
6

Here, you have a single method which receive two arguments. The first one is the parameters of the call (could be anything) and the second one is a context object. You can return anything serializable to JSON (or return nothing).

# Example

import { Parents, Container, Types } from '@ilos/core';

type HelloParamsType = {
  name: string,
};

@Container.handler({
  service: 'greeting',
  method: 'hello',
})
export class HelloAction extends Parents.Action {
  constructor(
  ) {
    super();
  }

  protected async handle(
    params: HelloParamsType,
    context: Types.ContextType,
  ): Promise<string> {
    return `Hello ${params.name}`;
  }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23