NextModelApiServerExpress
Api Server for ApiClient using NextModel package.
Features:
- Shared model for Server and Client.
- Allows to plug in every server side connector to connect Api to database
- Allows Api-Endpoint to de on a different domain
- Api Versioning
- Custom Routes and Actions
Roadmap / Where can i contribute
See GitHub project for current progress/tasks
- Fix Typos
- Add user credentials to queries
- Settings to configure cors headers
- Add more examples
- Add exists, join and subqueries
- There are already some tests, but not every test case is covered
TOC
Example
Custom Routes
The route configuration is done at the defined (shared) Model.
Default Routes:
all : POST /users
first : POST /users/first
last : POST /users/last
count : POST /users/count
insert : POST /users/create
update : POST /user/:id
delete : POST /user/:id/delete
Path
The routePath
defines the base route on the Server which contains the Api.
Default: ''
const BaseModel = static { return 'api'; } const User = ...
all : POST /api/users
first : POST /api/users/first
last : POST /api/users/last
count : POST /api/users/count
insert : POST /api/users/create
update : POST /api/user/:id
delete : POST /api/user/:id/delete
Version
The Api can be versioned with routeVersion
.
Default: ''
const BaseModel = static { return 'api'; } static { return 'v1'; } const User = ...
all : POST /api/v1/users
first : POST /api/v1/users/first
last : POST /api/v1/users/last
count : POST /api/v1/users/count
insert : POST /api/v1/users/create
update : POST /api/v1/user/:id
delete : POST /api/v1/user/:id/delete
Name
The model name in the route defaults to the tableName
, but can be overwritten by routeName
.
const BaseModel = static { return 'account'; } const User = ...
all : POST /accounts
first : POST /accounts/first
last : POST /accounts/last
count : POST /accounts/count
insert : POST /accounts/create
update : POST /account/:id
delete : POST /account/:id/delete
Postfix
The routePostfix
can be used to define a file name for the Url.
Default: ''
const BaseModel = static { return '.json'; } const User = ...
all : POST /users.json
first : POST /users/first.json
last : POST /users/last.json
count : POST /users/count.json
insert : POST /users/create.json
update : POST /user/:id.json
delete : POST /user/:id/delete.json
Action Path
The action url can be defined for every action.
Defaults:
- all:
''
- first:
'/first'
- last:
'/last'
- count:
'/count'
- create:
'/create'
- update:
''
- delete:
'/_delete'
const BaseModel = static { return '/all'; } static { return ''; } static { return '/update'; } const User = ...
all : POST /users/all
first : POST /users
last : POST /users/last
count : POST /users/count
insert : POST /users/create
update : POST /user/:id/update
delete : POST /user/:id/delete
Action Method
The method url can be defined for every action.
Default: 'POST'
Please Note: The default is POST for every route, cause the filter payload can be too large for query strings.
const BaseModel = static { return 'GET'; } static { return 'GET'; } static { return 'GET'; } static { return 'GET'; } static { return 'PATCH'; } static { return 'DELETE'; } const User = ...
all : GET /users
first : GET /users/first
last : GET /users/last
count : GET /users/count
insert : POST /users/create
update : PATCH /user/:id
delete : DELETE /user/:id/delete
Changelog
See history for more details.
0.1.0
**2017-04-05 First public release