Server
June 2, 2024 ยท View on GitHub
Installation
$ npm install autoserver
Usage
To run the server from the command line:
$ autoserver run
or from Node.js:
import { run } from 'autoserver'
run()
Configuration
The configuration can be passed directly as
command line or Node.js
options, but is usually specified using a
configuration file named
autoserver.config.yml in the current directory.
It can be divided into several files, use custom functions or import Node.js modules.
engine: 0
collections:
users:
description: User of the API
attributes:
id:
type: string
age:
type: integer
score:
type: number
alias: high_score
default: 10
validate:
minimum: 20
reports:
type: reports[]
reports:
attributes:
id:
type: string
content:
type: string
default:
database: mongodb
databases:
mongodb:
hostname: localhost
password: secret_mongodb_password
dbname: my_database_name
protocols:
http:
port: 5001
Data model
The configuration specifies the data model, including the list of collections, attributes and their relations to each other.
It also includes any logic related to authorization, readonly attributes, data validation, default values, computing and transforming attributes, aliasing and custom patch operators.
Plugins
Plugins can be used to extend functionalities such as
automatically adding timestamps and
created_by|updated_by attributes
Software quality
The following can also be configured: logging, performance monitoring, API documentation and limits.
Protocols
The server is protocol-agnostic. However, for the moment, the only supported protocol is HTTP.
Databases
The server is database-agnostic. The following databases are currently supported: an in-memory database and MongoDB.
Server (table of contents)
- How to specify the configuration
- Configuration file formats
- Breaking the configuration file into several parts
- Custom logic