WebTyped is a tool for generating strongly typed TypeScript code from your http://ASP.NET or http://ASP.NET/core Web Apis.
npm install @guimabdo/webtyped
WebTyped is a tool for generating strongly typed TypeScript code from your http://ASP.NET or http://ASP.NET/core Web Apis.
``
npm install @guimabdo/webtyped -g
npm install @guimabdo/webtyped-common
`
Create a webtyped.json configuration file in your project.
Example:
`javascript
{
"files": [
"../Controllers/*/.cs",
"../Models/*/.cs"
]
}
`
At the command line, run webtyped:
`batchfile`
webtyped
Or use 'watch' option for generating typescript code and start watching cs files:
`batchfile`
webtyped watch
Use generated services wherever you want:
`typescript
import { MyService } from './webtyped/
import { WebTypedFetchInvoker } from "@guimabdo/webtyped-common";
let inv = new WebTypedFetchInvoker(
let myService = new MyService(inv); //Generated from MyController.cs
myService.get().then(result => console.log(result));
`
`
npm install @guimabdo/webtyped-angular
`
webtyped.json
`javascript`
{
"files": [
"../Controllers/*/.cs",
"../Models/*/.cs"
],
"inject": {
"beforeServiceClass": [
"import { Injectable } from '@angular/core';",
"@Injectable({ providedIn: 'root' })"
]
},
}
Import the generated module and inject services when needed:
app.module.ts
`typescript
import { WebTypedNgModule } from '@guimabdo/webtyped-angular';
@NgModule({
imports: [
WebTypedNgModule.forRoot()
],
//Optionally set api base. Default is './'
providers: [
{
provide: 'API_BASE_URL',
useValue: '
}
]
})
export class AppModule {}
`
Usage:
some.component.ts (for example)
`typescript``
import { MyService } from './webtyped/
@Component({...})
export class SomeComponent {
constructor(myService: MyService){}
}
netcore 2.0 on dev machine