UNPKG

2.8 kBMarkdownView Raw
1![Dominion Node.js framework for RESTfull APIs](https://dominion.js.org/assets/logo.svg)
2
3# Dominion Node.js framework for RESTfull APIs
4[![Gitter](https://badges.gitter.im/dominion-framework/community.svg)](https://gitter.im/dominion-framework/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
5[![install size](https://packagephobia.now.sh/badge?p=@dominion-framework/dominion)](https://packagephobia.now.sh/result?p=@dominion-framework/dominion)
6
7Declarative Promise based Node.js framework for RESTful API
8
9## Installation
10```
11npm i @dominion-framework/dominion
12```
13
14## Quick start
15```
16npx dominion create hello
17npm start
18```
19This will run Node.js server with demo API's.
20Open http://localhost:7042/hello to check results and examine
21generated files in folder `components/hello` to see how it works.
22
23# Documentation
24
25Read full documentation on __[dominion.js.org](https://dominion.js.org/)__.
26
27# Features highlight
28
29### Clear Endpoints Declaration
30
31```js
32module.exports = {
33
34 factory: BooksFactory,
35
36 GET: [
37 // books?genre=western
38 function (genre = null) {
39 return BooksFactory.find({genre});
40 }
41 ],
42
43 POST: [
44 // books/
45 function () {
46 return BooksFactory.new(this.request.body)
47 .then(book => book.save());
48 }
49 ]
50}
51```
52
53
54### Automatic RESTful URLs
55```js
56// Endpoint URLs is build based on function arguments:
57
58function (limit = 10, offset = 0) { }
59// https://api.example.com/books?limit=42&offset=21
60
61
62function (libraryShelvesId, favoriteBooksId, orderBy = "") { }
63// https://api.example.com/library-shelves/42/favorite-books/84?orderBy=+author
64
65```
66
67### Models Schema Validation
68```js
69{
70 name: "Book",
71
72 properties: {
73 id: Property.id(),
74 name: Property.string().min(1).required(),
75 isbn: Property.string().pattern(/^\d-\d{3}-\d{5}-\d$/).example("0-330-25864-8"),
76 authorId: Property.model("Author"),
77 genre: Property.set(["Fantasy", "Science fiction", "Western", "Romance"]),
78 creationTime: Property.date().private(),
79 modificationTime: Property.date().private()
80 }
81 ...
82}
83```
84
85### Annotations
86```js
87function(isbn) {
88 // @path: books/isbn/(\d{1,5}[- ]\d{1,7}[- ]\d{1,6}[- ](?:\d|X))
89 // @model: Books
90 // @summary: Get book by ISBN number
91
92 return BooksFactory.get({isbn})
93}
94```
95
96### OpenAPI (Swagger) documentation
97
98Automatic OpenAPI documentation based on source code.
99
100
101### Zero Dependencies
102
103100Kb footprint Node.js framework with __no__ npm dependencies. If you also think, that
104you don't need npm to [left-pad](https://www.theregister.co.uk/2016/03/23/npm_left_pad_chaos/) a string.