web_api_base 1.3.1 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Application.d.ts +1 -0
- package/dist/Application.js +4 -0
- package/dist/Application.js.map +1 -1
- package/package.json +2 -1
- package/readme.md +86 -0
package/dist/Application.d.ts
CHANGED
package/dist/Application.js
CHANGED
|
@@ -22,12 +22,16 @@ class Application {
|
|
|
22
22
|
StartAsync() {
|
|
23
23
|
return __awaiter(this, void 0, void 0, function* () {
|
|
24
24
|
yield this.ApplicationConfiguration.StartAsync();
|
|
25
|
+
this.Express.use(express_1.default.json({ limit: 50 * 1024 * 1024 }));
|
|
25
26
|
this.Configure(this.ApplicationConfiguration);
|
|
26
27
|
this.Express.listen(this.ApplicationConfiguration.Port, this.ApplicationConfiguration.Host, () => {
|
|
27
28
|
console.log(`App running on ${this.ApplicationConfiguration.Host}:${this.ApplicationConfiguration.Port}`);
|
|
28
29
|
});
|
|
29
30
|
});
|
|
30
31
|
}
|
|
32
|
+
UseCors() {
|
|
33
|
+
this.Express.use(require('cors')());
|
|
34
|
+
}
|
|
31
35
|
}
|
|
32
36
|
exports.default = Application;
|
|
33
37
|
//# sourceMappingURL=Application.js.map
|
package/dist/Application.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Application.js","sourceRoot":"","sources":["../Application.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AACA,sDAAoC;AACpC,0FAAiE;AAIjE,MAA8B,WAAW;IAQrC;QAEI,IAAI,CAAC,wBAAwB,GAAG,IAAI,kCAAwB,EAAE,CAAC;QAE/D,IAAI,CAAC,OAAO,GAAG,IAAA,iBAAa,GAAE,CAAC;IAEnC,CAAC;IAGY,UAAU;;YAEnB,MAAM,IAAI,CAAC,wBAAwB,CAAC,UAAU,EAAE,CAAC;YAEjD,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,wBAAwB,CAAC,CAAC;YAE9C,IAAI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CAAC;IACxC,CAAC;CAMJ;AAxCD,8BAwCC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "web_api_base",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"description": "web api base",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
"run:tests": "npx jest"
|
|
15
15
|
},
|
|
16
16
|
"author": "adriano.marino1992@gmail.com",
|
|
17
|
+
"repository": "https://github.com/adrianomarino1992/web_api_base.git",
|
|
17
18
|
"license": "ISC",
|
|
18
19
|
"dependencies": {
|
|
19
20
|
"@types/express": "^4.17.15",
|
package/readme.md
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
# WEB_API_BASE
|
|
2
|
+
|
|
3
|
+
web_api_base is a npm packaged that allows to create web-apis like MVC of .NET
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install web_api_base
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
## Usage
|
|
15
|
+
|
|
16
|
+
First of all we need implement the abstract class __Application__.
|
|
17
|
+
After that, we need to create some controllers and, they must inherit the abstract class __ControllerBase__.
|
|
18
|
+
|
|
19
|
+
### SampleController.ts
|
|
20
|
+
|
|
21
|
+
```typescript
|
|
22
|
+
|
|
23
|
+
import { ControllerBase, ControllersDecorators as CD, HTTPVerbs as verbs } from "web_api_base";
|
|
24
|
+
|
|
25
|
+
@CD.Route("/sample")
|
|
26
|
+
export default class SampleController extends ControllerBase
|
|
27
|
+
{
|
|
28
|
+
@CD.Verb(verbs.GET)
|
|
29
|
+
@CD.Action("/hello")
|
|
30
|
+
public Hello() : void
|
|
31
|
+
{
|
|
32
|
+
this.OK({message: "Hello Word!"})
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
}
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### App.ts
|
|
39
|
+
|
|
40
|
+
```typescript
|
|
41
|
+
import SampleController from "./controllers/SampleController ";
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
import { ControllerBase, Application, IApplicationConfiguration, DependecyService } from "web_api_base";
|
|
45
|
+
|
|
46
|
+
export default class App extends Application
|
|
47
|
+
{
|
|
48
|
+
|
|
49
|
+
public override Configure(appConfig: IApplicationConfiguration): void
|
|
50
|
+
{
|
|
51
|
+
appConfig.Host = "0.0.0.0";
|
|
52
|
+
appConfig.Port = 5555;
|
|
53
|
+
|
|
54
|
+
//allow CORS
|
|
55
|
+
this.UseCors();
|
|
56
|
+
|
|
57
|
+
//register in DI service
|
|
58
|
+
DependecyService.Register(SampleController);
|
|
59
|
+
|
|
60
|
+
//append the controller in the pipe line of requests
|
|
61
|
+
ControllerBase.AppendController(SampleController,this);
|
|
62
|
+
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### Index.ts
|
|
68
|
+
|
|
69
|
+
```typescript
|
|
70
|
+
import Application from './Application';
|
|
71
|
+
|
|
72
|
+
new Application().StartAsync();
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
## Contributing
|
|
78
|
+
|
|
79
|
+
Pull requests are welcome. For major changes, please open an issue first
|
|
80
|
+
to discuss what you would like to change.
|
|
81
|
+
|
|
82
|
+
Please make sure to update tests as appropriate.
|
|
83
|
+
|
|
84
|
+
## License
|
|
85
|
+
|
|
86
|
+
[MIT](https://choosealicense.com/licenses/mit/)
|