Skip to content

lanicon/Route.Generator

 
 

Repository files navigation

Master

Build Status

Code Gen

Build Status

Package NuGet Stable Downloads
Route.Generator Route.Generator Route.Generator

Install NuGet package

PM> Install-Package Route.Generator

Edit Startup.cs

Insert code services.AddRouteAnalyzer(); and required using directive into Startup.cs as follows.

using Route.Generator; // Add
....
public void ConfigureServices(IServiceCollection services)
{
    services.AddMvc();
    services.AddRouteAnalyzer(); // Add
}
....

View Routes via Browser

Eg. input http://localhost:27634/routes.html

screenshot

Eg. input http://localhost:27634/routes, the address is used to generate async methods, 
please make it accessible.

screenshot

Generate Routes and Async Methods

If you want more powerful features, you can install Route.Generator.CLI to Generate Routes Generated Files

PM> Install-Package Route.Generator.CLI
PM> routegen gen -p <Your project name> -u <The base address>
Eg. routegen gen -p Api -u http://localhost:27634/

Command-line Options

command description
-p Your project name
-u The base address
-o The out put file name. default name is Routes.Generated.cs.
-g Whether generate async method or not, 1 or true meanings will generate, otherwise will not.

Technologies

Unit Tests

Supported Http Methods

  • [Get]
  • [Post]
  • [Delete]
  • [Post]
  • [Put]

Generated Files

Route Generator Project

Examples

[Route("api/[controller]/[action]")]
[ApiController]
public class ExampleController : StandardController
{
    [HttpGet("{key}")]
    public Dictionary<string, string> GetVlues(string key, string value)
    {
        return this.ResponseDictionary(key, value, nameof(this.GetVlues));
    }

    [HttpPost]
    public Dictionary<string, string> Edit(PointModel model)
    {
        return this.ResponseDictionary(null, null, nameof(this.Edit));
    }

    [HttpDelete]
    public Dictionary<string, string> Delete(string id)
    {
        return this.ResponseDictionary(null, null, nameof(this.Delete));
    }
}
/// <summary>
/// <see cref="Controllers.ExampleController"/>
/// </summary>
public class ExampleRoute
{
    /// <summary>
    /// <see cref="Controllers.ExampleController.GetVlues"/>
    /// </summary>
    public const string GetVlues = "/api/Example/GetVlues/{key}";
    public static async Task<T> GetVluesAsync<T>(string key, string value)
    {
        var routeInfo = new RouteInfo
        {
            HttpMethods = "GET",
            Path = GetVlues,
            Parameters = new List<ParameterInfo>
            {
                new ParameterInfo() {Name = "key", Type = "string"},
                new ParameterInfo() {Name = "value", Type = "string"},
            }
        };
        return await HttpClientAsync.Async<T>(routeInfo, key, value);
    }

    /// <summary>
    /// <see cref="Controllers.ExampleController.Edit"/>
    /// </summary>
    public const string Edit = "/api/Example/Edit";
    public static async Task<T> EditAsync<T>(Api.Models.PointModel model)
    {
        var routeInfo = new RouteInfo
        {
            HttpMethods = "POST",
            Path = Edit,
            Parameters = new List<ParameterInfo>
            {
                new ParameterInfo() {Name = "model", Type = "Api.Models.PointModel"},
            }
        };
        return await HttpClientAsync.Async<T>(routeInfo, model);
    }

    /// <summary>
    /// <see cref="Controllers.ExampleController.Delete"/>
    /// </summary>
    public const string Delete = "/api/Example/Delete";
    public static async Task<T> DeleteAsync<T>(string id)
    {
        var routeInfo = new RouteInfo
        {
            HttpMethods = "DELETE",
            Path = Delete,
            Parameters = new List<ParameterInfo>
            {
                new ParameterInfo() {Name = "id", Type = "string"},
            }
        };
        return await HttpClientAsync.Async<T>(routeInfo, id);
    }
}
/// <summary>
/// <see cref="Controllers.HomeController"/>
/// </summary>
public class HomeRoute
{
    /// <summary>
    /// <see cref="Controllers.HomeController.Index"/>
    /// </summary>
    public const string Index = "/Admin/Home/Index";

    /// <summary>
    /// <see cref="Controllers.HomeController.About"/>
    /// </summary>
    public const string About = "/Admin/Home/About";

    /// <summary>
    /// <see cref="Controllers.HomeController.Contact"/>
    /// </summary>
    public const string Contact = "/Admin/Home/Contact";

    /// <summary>
    /// <see cref="Controllers.HomeController.Privacy"/>
    /// </summary>
    public const string Privacy = "/Admin/Home/Privacy";

    /// <summary>
    /// <see cref="Controllers.HomeController.Error"/>
    /// </summary>
    public const string Error = "/Admin/Home/Error";
}

My projects

About

.Net Core Api & Mvc .NET Core command-line (CLI) tool to generate Route source files. Generate route automatically, and you can call API like local method.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 74.1%
  • CSS 25.8%
  • PowerShell 0.1%