nanium-channel-rest
v1.0.6
Published
a nanium request channel that creates REST-style endpoints for the nanium services
Downloads
73
Readme
nanium-channel-rest
A nanium request channel that creates REST-style endpoints for the nanium services
Install
npm install nanium-channel-rest
Usage
import { Nanium } from 'nanium/core';
import { NaniumRestChannel } from 'nanium-channel-rest';
const httpServer = http.createServer((_req, _res) => {});
httpServer.listen(3000);
await Nanium.addManager(new NaniumNodejsProvider({
servicePath: 'services',
requestChannels: [
new NaniumRestChannel({
apiBasePath: '/api',
server: httpServer
})
]
}));
This creates an HTTP endpoint for each service based on the service name.
HTTP methods
Which HTTP method is used depends on the name of the contract.ts file;
GET:
- get.contract.ts
- query.contract.ts
PUT:
- update.contract.ts
- change.contract.ts
- store.contract.ts
- put.contract.ts
DELETE:
- remove.contract.ts
- delete.contract.ts
POST:
- create.contract.ts
- add.contract.ts
- post.contract.ts
- everything else
HTTP request deserialization
Properties of HTTP-header will be available in request.head. Properties of HTTP-body and querystring will be available in request.body. The request will have two additional properties:
- request['$$rawBody'] = raw body as buffer;
- request['$$requestSource'] = remoteAddress or 'x-forwarded-for' header