web_api_base 2.5.0 → 2.5.2
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/package.json +1 -1
- package/readme.md +34 -10
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -14,19 +14,28 @@ npm install web_api_base
|
|
|
14
14
|
## Usage
|
|
15
15
|
|
|
16
16
|
First of all we need implement the abstract class __Application__.
|
|
17
|
-
After that, we need to create some controllers and
|
|
17
|
+
After that, we need to create some controllers and they must inherit the abstract class __ControllerBase__.
|
|
18
18
|
|
|
19
|
-
### SampleController.ts
|
|
19
|
+
### ./controllers/SampleController.ts
|
|
20
20
|
|
|
21
21
|
```typescript
|
|
22
22
|
|
|
23
|
-
import { ControllerBase,
|
|
23
|
+
import { ControllerBase, HTTPVerbs as verbs, Use, Verb, Route, Action } from "web_api_base";
|
|
24
|
+
/*
|
|
24
25
|
|
|
25
|
-
|
|
26
|
+
we can use this class to acess all decorators centralized
|
|
27
|
+
import { ControllerDecorators as CD } from "web_api_base";
|
|
28
|
+
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
//@CD.Route("/sample")
|
|
32
|
+
@Route("/sample")
|
|
26
33
|
export default class SampleController extends ControllerBase
|
|
27
34
|
{
|
|
28
|
-
|
|
29
|
-
@
|
|
35
|
+
//@CD.Verb(verbs.GET)
|
|
36
|
+
@Verb(verbs.GET)
|
|
37
|
+
//@CD.Action("/hello")
|
|
38
|
+
@Action("/hello")
|
|
30
39
|
public Hello() : void
|
|
31
40
|
{
|
|
32
41
|
this.OK({message: "Hello Word!"})
|
|
@@ -48,17 +57,32 @@ export default class App extends Application
|
|
|
48
57
|
|
|
49
58
|
public override Configure(appConfig: IApplicationConfiguration): void
|
|
50
59
|
{
|
|
51
|
-
|
|
52
|
-
appConfig.
|
|
60
|
+
//to define the host use this property, if that property is not changed, the default value will be 0.0.0.0
|
|
61
|
+
appConfig.Host = "127.0.0.1";
|
|
62
|
+
//to define the app port use this property, if that property is not changed, the default value will be 5555
|
|
63
|
+
appConfig.Port = 1234;
|
|
53
64
|
|
|
54
65
|
//allow CORS
|
|
55
66
|
this.UseCors();
|
|
56
67
|
|
|
57
68
|
//register in DI service
|
|
58
69
|
DependecyService.Register(SampleController);
|
|
70
|
+
|
|
71
|
+
*/
|
|
72
|
+
if the controlles follow the naming rules, the method UseControllers will automatically append them
|
|
73
|
+
|
|
74
|
+
rootDir -
|
|
75
|
+
|
|
|
76
|
+
| - controllers -
|
|
77
|
+
| - <Name>Controller.ts
|
|
78
|
+
|
|
|
79
|
+
| - App.ts //the class that inherit the Application
|
|
80
|
+
|
|
81
|
+
*/
|
|
82
|
+
this.UseControllers();
|
|
59
83
|
|
|
60
|
-
//
|
|
61
|
-
ControllerBase.AppendController(SampleController,this);
|
|
84
|
+
//if not, we can append manually using the method bellow
|
|
85
|
+
//ControllerBase.AppendController(SampleController,this);
|
|
62
86
|
|
|
63
87
|
}
|
|
64
88
|
}
|