【Netcore】使用 Magic生成器 ,零代码实现CRUD - HTTP REST 之接口

 

软件介绍:git

Magic是一个CRUD后端生成器,内置于ASP.NET内核中。它的目的是让你“神奇地”作一些无聊的事情,经过使用自动化技术,建立80%的CRUD端点,自动包装MySQL或MS SQL Server数据库,同时你能够专一于有趣的事情。github

 

1、参考文档数据库

一、适合 ASP.NET Core 的超级-DRY开发npm

二、Magic 官网:https://polterguy.github.io/getting-started/json

 

2、实现步骤:后端

Getting started

To get started with Magic you’ll need the following installed.服务器

  1. MySQL or Microsoft SQL Server.app

  2. Visual Studio Code, or Visual Studio if you’re on Windowsless

  3. NodeJS - To serve the frontend/dashboardfrontend

  4. Angular, which is installed using npm install -g @angular/cli after installing NodeJS

  5. DotNet CLI - Unless you’re using Visual Studio on Windows

 

List of what to do

  1. Open Visual Studio Code in your magic folder

  2. Edit your appsettings.json file, and modify your MySQL and/or MSSQL connection strings

  3. Open one terminal window and go to magic.backend

  4. Run dotnet run in the magic.backend terminal

  5. Open another terminal window and go to frontend

  6. Run npm install in this terminal

  7. When npm install from above is done, run ng serve in the frontend terminal

  8. Open your browser and point it to http://localhost:4200

Creating your first CRUD Web API

  1. Login with “root/root” as your username/password

  2. Click the “Crudify” menu item

  3. Choose your database and your table

  4. Click the “Crudify” button

When you have created your first CRUD endpoints, you can click the “Endpoints” menu item, and try out your newly created HTTP REST endpoints.

若是你在一家咨询公司工做,可能每一年都会启动几个具备相似需求类型的新项目,其中须要解决每一个新项目的共性。了解了客户端需求和一些初始实现以后,即可以使用超级 DRY 方法在几秒钟内完成整个项目。固然,经过标识常见模块(如身份验证和受权),能够进一步重用项目中的元素组合。经过在常见 Web API 项目中实现这些模块,能够将它们应用到任何新项目中,这些新项目会带来与你之前看到过的相似的问题。

为了方便记录,此操做听起来很简单,但事实上避免重复很难。它须要反复重构的意愿。完成重构时,还须要进一步进行重构。但好处是不容忽视的。DRY 原则可让你近乎魔术般地建立代码,只需挥动基架魔杖,并借用现有部件组合模块。

最后,这里阐述的原则能够帮助你利用现有最佳作法建立本身的 Web API,同时避免重复。这种方法能够带来不少好处,但愿它能够帮助你领会到 DRY 的美妙之处。

 

 

 

尽管出于学术缘由,Magic的大部分源代码都是公开的,但它并非开源的或免费的软件,咱们会对您要运行Magic的每一个服务器/主机名/DNS记录收取费用。不过,在本地开发机器上评估和使用Magic是免费的。若是您想使用Magic建立免费的开源软件,咱们还能够给您一个免费的许可证密钥。请在此处或随附的许可证文件中阅读更多信息。

 

相关文章
相关标签/搜索