Registered as js-data-express
in NPM.
npm i --save js-data-express@rc js-data@rc
import { Router } from 'js-data-express';
const adapter = new Router();
var Router = require('js-data-express').Router;
var adapter = new Router();
Classes
Members
-
<static> Router
-
Router class.
DetailsType Source See Constructor index.js, line 345 - Router
Examplesimport { Router } from 'js-data-express'; const adapter = new Router();
var Router = require('js-data-express').Router; var adapter = new Router();
-
<static> version
-
Details of the current version of the
js-data-express
module.Properties:
Name Type Description version.full
String The full semver value.
version.major
Number The major version number.
version.minor
Number The minor version number.
version.patch
Number The patch version number.
version.alpha
String | Boolean The alpha version value, otherwise
false
if the current version is not alpha.version.beta
String | Boolean The beta version value, otherwise
false
if the current version is not beta.Examplesimport { version } from 'js-data-express'; console.log(version.full);
var version = require('js-data-express').version; console.log(version.full);
Methods
-
<static> mount(app, store, config)
-
Convenience method that mounts queryParser and a store.
Method parameters:Name Type Argument Description app
* store
Object Instance of
Mapper
,Container
,SimpleStore
, orDataStore
.config
Config | String <optional>
Configuration options.
Examplesimport express from 'express'; import { mount, queryParser, Router } from 'js-data-express'; import { Container } from 'js-data'; const app = express(); const store = new Container(); const UserMapper = store.defineMapper('user'); const CommentMapper = store.defineMapper('comment'); mount(app, store);
mount(app, store, '/api');
Type Definitions
-
ActionHandler(component, req)
-
Custom defined method that retrieves data/results for an endpoint
Method parameters:Name Type Description component
Object Instance of
Mapper
,Container
,SimpleStore
, orDataStore
.req
Object HTTP(S) Request Object
Return value:Type Description Promise Promise that resolves with the result.
Example(component, req) => { return new Promise((resolve, reject) => { // ..some logic return resolve(results) }) }
-
Config
-
Configuration options for endpoints, actions, & request/response
Properties:
Name Type Argument Description getEndpoint
Endpoint <optional>
Define endpoints with custom method
create
CreateConfig <optional>
create action configs
createMany
CreateManyConfig <optional>
createMany action configs
destroy
DestroyConfig <optional>
destroy action configs
destroyAll
DestroyAllConfig <optional>
destroyAll action configs
find
FindConfig <optional>
find action configs
findAll
FindAllConfig <optional>
findAll action configs
toJSON
Serializer | Boolean <optional>
Define custom toJSON method for response results
update
UpdateConfig <optional>
update action configs
updateAll
UpdateAllConfig <optional>
updateAll action configs
updateMany
UpdateManyConfig <optional>
updateMany action configs
-
CreateConfig
-
create action configs
-
CreateManyConfig
-
createMany action configs
-
DestroyAllConfig
-
destroyAll action configs
-
DestroyConfig
-
destroy action configs
-
Endpoint(mapper)
-
Define endpoint path with custom logic
Method parameters:Name Type Description mapper
Object Component Mapper object
-
FindAllConfig
-
findAll action configs
-
FindConfig
-
find action configs
-
RequestHandler(req, res, next)
-
A middleware method invoked on all requests
Method parameters:Name Type Description req
Object HTTP(S) Request Object
res
Object HTTP(S) Response Object
next
Function Express
next()
callback to continue the chain -
ResponseHandler(req, res, next)
-
A method that handles all responses
Method parameters:Name Type Description req
Object HTTP(S) Request Object
res
Object HTTP(S) Response Object
next
Function Express
next()
callback to continue the chain -
Serializer(component, result, opts)
-
Method parameters:
Name Type Description component
Object Instance of
Mapper
,Container
,SimpleStore
, orDataStore
.result
Object The result of the endpoint's ActionHandler.
opts
Object Configuration options.
-
UpdateAllConfig
-
UpdateAllConfig action configs
-
UpdateConfig
-
update action configs
-
UpdateManyConfig
-
updateMany action configs