Final
This is a very experimental proof of concept for a server framework. It takes ideas from ES6+ and React to see if there's a more enjoyable, versatile way to create APIs.
Key concepts are:
Classes
Each endpoint has a class, which extends the component class. The main method of the class is respond
which decides what is returned upon each request.
Lifecycle
Each component has a lifecycle, with names similar to the lifecycle components of React components.
Decorators
Decorators are used to add actions and in-memory state to components. The example decorator that's included is for ArangoDB. A reduxConnect
decorator is also currently part of the library.
WebSockets
WebSocket-functionality is built-in (at present). Depending on how you wish to use the library, you can have components that repeat their lifecycle whenever state is changed. This is most useful for WebSocket servers becuase there may be multiple responses per connection. An http
request will fire response
onece, but a WebSocket connection might do it many times.
Installation
Use yarn
or npm
to install like so. Arango is optional, and it may also be possible to use without Babel, but documentation assumes you can use decorators and class properties.
yarn add final-server final-arango
yarn add --dev @babel/core @babel/preset-env @babel/plugin-proposal-class-properties @babel/preset-stage-0
Usage
See the /examples
and files matching the patter **/*.test.js
for more usage and explanation. Be warned the API will change a lot.
/* The `findDecorator` adds a few funtions to the class, like `this.findOne`.*/@@Component /* The path decides what requests will match this component and the params. */ path = '/post/:post?' /* Define the schema which is enforced by the arango decorator on `save` commands. */ schema = UserSchema uniques = 'email' async { console console const output = await thisactions return data: players: thispropsplayers output } Final