Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

T4 Web API C# to Typescript class library [closed]

I've recently asked about C# classes to T4 viewmodels, but this is different so I separated it out into a second question

I'd like to automate the generate of a client library in typescript that includes endpoints for every web api method that is adorned with the HttpGet, Post, Put, Delete, Patch attributes.

This would generate the jQuery ajax calls to interface with the web api calls.

Anyone seen anything like this? I would LOVE to save some time having to hack together a T4 script.

Thanks!

like image 539
James Hancock Avatar asked Oct 17 '13 21:10

James Hancock


People also ask

What is T4 in Entity Framework?

t4 template is used to scaffold a DbContext class for the database, and the EntityType. t4 template is used to scaffold entity type classes for each table and view in the database.

What is .TT file in C#?

TT stands for - Visual Studio Text Template is a software development tool created by the Microsoft. Further explanation - TT file contains text block and control logic used for generating new files. To write the Text Template file we can use either - Visual C# or Visual Basic Code.

What is the purpose of using T4 templates?

Design-time T4 text templates let you generate program code and other files in your Visual Studio project. Typically, you write the templates so that they vary the code that they generate according to data from a model. A model is a file or database that contains key information about your application's requirements.


1 Answers

It looks like this guy used T4 to generate a TypeScript proxy to his Web API service. http://galador.net/codeblog/post/2013/11/12/Client-Side-Web-Application-primer.aspx

However, if your only client will be from the browser, you may want to consider using SignalR instead with this T4 template. https://gist.github.com/robfe/4583549

There are also a few libraries that generate TypeScript definition files from CLR types:

  • ToTypeScriptD
  • TypeLITE
like image 97
Oran Dennison Avatar answered Oct 13 '22 01:10

Oran Dennison