npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

webtyped

v0.0.0

Published

WebTyped is a tool for generating strongly typed TypeScript code from your http://ASP.NET or http://ASP.NET/core Web Apis.

Downloads

7

Readme

Build status

WebTyped Latest version

WebTyped is a tool for generating strongly typed TypeScript code from your http://ASP.NET or http://ASP.NET/core Web Apis.

Quick Start

npm install @guimabdo/webtyped -g
npm install @guimabdo/webtyped-common
npm install @guimabdo/webtyped-[fetch|jquery|angular|angular4]

Create a webtyped.json configuration file in your project. Example:

{
	"files": [
		"../Controllers/**/*.cs",
		"../Models/**/*.cs"
	],
	"outDir": "./webtyped/", //optional, default: "webtyped",
	"serviceMode": "angular", //optional, default: "fetch", current options: "fetch", "angular", "angular4" or "jquery"
	"trims": ["My.Namespace"], //optional
	"baseModule": "WebApis", //optional
	"keepPropsCase": false, //optional, default: false. May be useful with old versions of Asp.Net WebApi
	"clear": true //optional, default: true. Delete typescript files that are not part of the current generation
}

At the command line, run webtyped:

webtyped

Or use 'watch' option for generating typescript code and start watching cs files:

webtyped watch

Use generated services wherever you want:

import { MyService } from './webtyped/<services-folder>';
let myService = new MyService(); //Generated from MyController.cs
myService.get().then(result => console.log(result));

Angular

webtyped.json

  • serviceMode: "angular" for >=6.0.0
  • serviceMode: "angular4" for >=4.3.0 <6.0.0

Import the generated module and inject services when needed:

app.module.ts

import { WebTypedGeneratedModule } from './webtyped';
@NgModule({
	imports: [WebTypedGeneratedModule.forRoot()]
})
export class AppModule {}

some.component.ts (for example)

import { MyService } from './webtyped/<services-folder>';
@Component({...})
export class SomeComponent {
	constructor(myService: MyService){}
}

Requirements

netcore 2.0 on dev machine

WebTyped.Annotations Latest version

Attributes for changing services/models generator behaviour.

ClientTypeAttribute

Use this attribute for mapping a Server Model to an existing Client Type so it won't be transpiled by the generator.

  • typeName: correspondent client type name, or empty if it has the same name as the server type.
  • module: type module, leave it empty if the type is globally visible.

Generated API services will know how to resolve the type.

example:

[WebTyped.Annotations.ClientType(module: "primeng/components/common/selectitem")]
public class SelectItem { 
    public string Label { get; set; }
    public long Value { get; set; }
}

NamedTupleAttribute

Sometimes your application have lots of multiparameted webapis. Instead of creating a Model for each webapi method, you may want to use Named Tuples like this:

[HttpPost("")]
public void Save([FromBody](name: string, birthdate: DateTime, somethingElse: number) parameters) {[
    ...
}

This will be transpiled to the client accordingly to .NET compiled tuple field names (Item1, Item2, Item3, ...), otherwise deserialization will not work when server receives the data. This will result in a non-friendly usage in client:

myService.save({ item1: "John", item2: "2010-12-01", item3: 42});

Decorating the method parameter with NamedTuple attribute makes the generator create the client function parameter using the original field names. This function will change the parameter field names (to item1, item2...) before sending it to the server. So the usage becomes:

myService.save({ name: "John", birthdate: "2010-12-01", somethingElse: 42});