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