Skip to content

amerina/EasyAPICore

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

EasyAPICore

The Controller API is automatically generated by convention

Simplest Usage

  1. Create ASP.NET Core WebApi(Or MVC) Project

    dotnet new webapi -o SampleWebAPI
  2. Install components via .Net CLI

    dotnet add package EasyAPICore --version 1.0.3
  3. Add new SampleService

    using EasyAPICore;
    using Microsoft.AspNetCore.Mvc;
    using System;
    
    namespace SampleWebAPI
    {
        public class SampleService : IEasyAPI
        {
            public BookReadDto Create(BookDto book)
            {
                return new BookReadDto
                {
                    Id = new Random().Next(1, 100),
                    Name = book.Name,
                    Description = book.Description
                };
            }
    
            public string Get(int id)
            {
                var dto = new BookReadDto
                {
                    Id = id,
                    Name = "Three body",
                    Description = "The Trisolaran Dark Forest"
                };
                return dto.ToString();
            }
    
            public string Delete(int id)
            {
                var dto = new BookReadDto
                {
                    Id = id,
                    Name = "Three body",
                    Description = "The Trisolaran Dark Forest"
                };
                return $"Delete {dto.ToString()} Success!" ;
            }
        }
    
        public class BookDto
        {
            /// <summary>
            /// Book Name
            /// </summary>
            public string Name { get; set; }
    
            /// <summary>
            /// Book Description
            /// </summary>
            public string Description { get; set; }
        }
    
        public class BookReadDto
        {
            /// <summary>
            /// Book Id
            /// </summary>
            public int Id { get; set; }
    
            /// <summary>
            /// Book Name
            /// </summary>
            public string Name { get; set; }
    
            /// <summary>
            /// Book Description
            /// </summary>
            public string Description { get; set; }
    
            public override string ToString()
            {
                return $"Book ID:{Id},Book Name:{Name},Book Description:{Description}";
            }
        }
    }
  4. Registered EasyAPICore

    public void ConfigureServices(IServiceCollection services)
    {
    	 //Register Swagger
         services.AddSwaggerGen(c =>
         {
             c.SwaggerDoc("v1", new OpenApiInfo { Title = "SampleWebAPI", Version = "v1" });
    
              //Must Add this
               c.DocInclusionPredicate((docName, description) => true);
          });
          services.AddEasyAPICore();
    }
  5. Add Middleware EasyAPICore

    app.UseEasyAPICore();
  6. Run Sample

    dotnet run

    00

Advanced Usage

Reference project

Thanks for following project.

About

Easy auto generate api by application service.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages