moleculer-web
Advanced tools
Changelog
0.5.0 (2017-09-12)
<a name="0.4.4"></a>
Changelog
0.4.1 (2017-07-24)
publish: false
action propertiesmodule.exports = {
name: "test",
actions: {
dangerZone: {
publish: false,
handler(ctx) {
return "You cannot call this action via API Gateway!";
}
}
}
};
The route
has a callOptions
property which is passed to broker.call
. So you can set timeout
, retryCount
or fallbackResponse
options for routes.
broker.createService(ApiGatewayService, {
settings: {
routes: [{
callOptions: {
timeout: 1000, // 1 sec
retryCount: 0,
//fallbackResponse: { ... },
// or
//fallbackResponse(ctx, err) { ... }
}
}]
}
});
<a name="0.4.0"></a>
Changelog
0.4.0 (2017-07-07)
GET /
calls the list
action instead of find
. The reason is list
action in moleculer-db
is support paginationctx.params = Object.assign({}, body, query, params)
.onBeforeCall
before authorize
in request flow. So you can also reach unauthorized requests in onBeforeCall
handler.sendResponse
method has new arguments: sendResponse(ctx, route, req, res, data, responseType)
<a name="0.3.3"></a>
Changelog
0.3.3 (2017-06-07)
There is available to use custom function in aliases. In this case you got req
& res
and you should return with the response. Use it for example file uploads. You can find example in the full example.
Usage
...
aliases: {
"add/:a/:b": "math.add",
"GET sub": "math.sub",
"POST upload"(route, req, res) {
//Do something and call res.end()
}
}
...
camelCaseNames
route settingThere is a new camelCaseNames
option in route setting. If it is true, the service will convert the received action name to camelCase name.
Usage
broker.createService(ApiGatewayService, {
settings: {
routes: [{
camelCaseNames: true
}]
}
});
broker.createService({
name: "test",
actions: {
sayHi(ctx) {
return "Hi!"
}
}
});
// Start server
broker.start();
In the above example the sayHi
action can be called with http://localhost:3000/test/say-hi as well.
<a name="0.3.2"></a>
Changelog
0.3.2 (2017-06-02)
Available errors:
| Class | Params | Description |
| ----- | ------ | ----------- |
|UnAuthorizedError
|type
, data
| Unauthorized HTTP error (401) |
|ForbiddenError
|type
, data
| Forbidden HTTP error (403) |
|BadRequestError
|type
, data
| Bad Request HTTP error (400) |
Type contants:
ERR_NO_TOKEN
ERR_INVALID_TOKEN
ERR_UNABLE_DECODE_PARAM
Usage
const { UnAuthorizedError, ERR_NO_TOKEN } = require("moleculer-web").Errors;
...
actions: {
update(ctx) {
if(!ctx.meta.user)
return Promise.reject(new UnAuthorizedError(ERR_NO_TOKEN));
}
}
...
<a name="0.3.1"></a>
Changelog
0.3.1 (2017-06-02)
It is possible to use RESTful aliases which routed to CRUD service actions.
Usage
broker.createService(ApiGatewayService, {
settings: {
routes: [{
// RESTful aliases
aliases: {
"REST posts": "posts"
}
}]
}
});
// Start server
broker.start();
The "REST posts": "posts"
will be extracted to these aliases:
"GET posts": "posts.find",
"GET posts/:id": "posts.get",
"POST posts": "posts.create",
"PUT posts/:id": "posts.update",
"DELETE posts/:id": "posts.remove"
Example: examples/rest
<a name="0.3.0"></a>