frhagn / Typewriter

Automatic TypeScript template generation from C# source files
http://frhagn.github.io/Typewriter
Apache License 2.0
536 stars 132 forks source link

Web API extensions for ASP.NET Core 1.0 #115

Open jods4 opened 8 years ago

jods4 commented 8 years ago

I know Core is not officially supported yet, but it works fine enough for me.

That said, the attributed routing in ASP.NET Core supports additional variants that don't exist in 4.5. It would be nice if Typewriter could support them in its Web API extensions, i.e. $Url.

In particular, all http attributes (HttpGet & co) implement IRouteTemplateProvider and are used to indicate routes. Also, apparently [controller] is the new {controller}...

[Route("api/[controller]")]
public class FrobController
{
  [HttpGet("bar")]
  public int Whatever() => 42;
}

Correct route above would be GET api/frob/bar.

frhagn commented 8 years ago

Hi @jods4, I have to read up some more on the core docs before I can make a proper extension for the new routing apis so this probably won't be included until Typewriter 2.x. I've added support for the [controller] and [action] tokens in the current implementation so you should be able to use them at least.

jods4 commented 8 years ago

@frhagn Thanks! In the meantime I'm using my own $ActionRoute method, which contains the minimum needed to support our patterns (we do use HttpGet("{id}") for example).

I think the official doc is not ready yet <_< https://docs.asp.net/en/latest/mvc/controllers/routing.html