GithubHelp home page GithubHelp logo

lanicon / route.generator Goto Github PK

View Code? Open in Web Editor NEW

This project forked from 188867052/route.generator

0.0 1.0 0.0 1.81 MB

.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.

Home Page: https://www.nuget.org/packages/Route.Generator

License: MIT License

C# 74.03% CSS 25.84% PowerShell 0.13%

route.generator's Introduction

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

route.generator's People

Contributors

188867052 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.