This article is available at github.com/chengxy-nds…

Hello, I’m Rich

Today, I would like to introduce a highly efficient and agile development tool called magic-API that I am using, and share my experience of using it in my work

origin

Why do I use this tool first?

Recently, I started a new project, the business is not complex, that kind of typical management system, product requirements to support global page configuration, all front-end configuration must be returned through the interface, such as: simple conditions such as query drop-down box (enable, disable), internationalization, must achieve full dynamic configuration.

In fact, as long as the staff enough time enough, these are no problem, but the problem is that the project to the online cycle of more than 10 days, and the development time is less than 10 days, time is tight and not to add people, the life of the bottom programmer is really difficult.

But the way is always more than difficult, my former colleague brother recommended this tool to me, and then really fragrant, ha ha ~

Magic-api is a Rapid development framework based on Java interface, writing interface will be completed through the UI interface provided by Magic-API, automatically mapped to HTTP interface, Without defining Controller, Service, Dao, Mapper, XML, VO and other Java objects, common HTTP API interface development can be completed.

Here is the official introduction of the tool, but I don’t seem to understand what it does. Let’s demonstrate it and you will find it very cool

The environment

First, POP.xml introduces the magic-API core package magic-API-spring-boot-starter

  <dependency>
      <groupId>org.ssssssss</groupId>
      <artifactId>magic-api-spring-boot-starter</artifactId>
      <version>0.71.</version>
  </dependency>

  <dependency>
      <groupId>mysql</groupId>
      <artifactId>mysql-connector-java</artifactId>
      <scope>runtime</scope>
  </dependency>
Copy the code

Application. Yml configuration is easier, database (no database operation can not write) and magic- API basic information

Magic-api: /magic/web # UI request interface and UI service address:9999
spring:
  datasource:
    driver-class-name: com.mysql.jdbc.Driver
    password: xinzhifu521
    url: jdbc:mysql: / / 47.93.6.5:3306 /magic-api
    username: root
    
Copy the code

Good ~ to this environment to build complete!


First of all, it is verbose. Especially when the time limit is tight and the functions need to be iterated quickly, the development specification should be strictly implemented and the time limit should not be delayed. Even the simplest API interface, Also need to write corresponding Controller, Service, Dao, Mapper, DTO, VO and other classes, although these basic coding has the corresponding code generator, but it is still quite troublesome to maintain, magic-API plays a very good auxiliary role, less to write a lot of code.

practice

Direct access to the http://127.0.0.1:9999/magic/web open magic – API visual interface, see the following interface.

Create a group whereGrouping prefixIs the access root of a set of APIS, equivalent to@Controller("/order")Annotation.The interfaces are then created in the grouporder_detail, configure basic interface information, such as interface name, request path, request method, request parameters, and request headerreturnReturns the content

return'Little rich is the most handsome'Copy the code

To access the page you just created the full path of the interface, http://127.0.0.1:9999/order/order_detail, found that have successfully return data.

Or you can just spell itJSONFormat data is returned directly

If the URL passes /order_detail/{id}, import the request module to get the parameters

import request;
a = path.id
Copy the code

At this point, a simple API interface is developed, and we have not yet written a single line of code in the project

But the above is only static data, in the actual development often have to deal with the database,magic-apiOffers something similar topythonModular components in development, such as introductionimport dbModule, directly executedSQLThe statement returnsJSONFormat data, omitting many intermediate steps. magic-apiGrammar andJavaIt’s not that different, but it’s a little more streamlined, and it’s not expensive to learn once you’ve written Java, like the common JavaforCycles, there will also be ordinary sumslambdaMultiple ways to write it.

var sum = 0;
var list = [1.2.3.4.5];
for(val in list){
    sum = sum + val;
}

list.each(it => sum+= it + 1)
Copy the code

Here I only briefly introduced the use, there are a lot of advanced features, such as: call Java API, integration redis, Mongo, etc., interested students look at the official documentation, it also provides a lot of syntax demo, ready to use.

Address: http://140.143.210.90:9999/magic/web/index.html

tips

Magic-api played a great role in the rush period of my whole project, saving more than half of the development time. It not only significantly improved the efficiency of back-end development interface, but also greatly helped front-end joint adjustment.

The front and back ends define the data structure from the beginning, the back end quickly provides static data interface, the front end uses real interface debugging, and the back end adds business logic and seamlessly replaces it with real data, so as to achieve synchronous development, and the front end does not need to write pseudo-code and other interface debugging.

Although magic-API can improve the development efficiency, but in the actual application, I only dare to use it in some relatively simple logic, configuration class interface, and is to provide static interface for the front end quickly, the core business or according to the “rules”, after all, system stability, security is the most important.

Sorted out hundreds of various kinds of technical e-books, there is a need for the students public number [programmer point matter] within the reply [666] self. The technology group is almost full, want to enter the students can add my friend, and the big guys blow technology together.