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

  • 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【 References 】

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
Server: port: 9999 Spring: datasource: driver-class-name: . Com. Mysql. JDBC Driver password: xinzhifu521 url: JDBC: mysql: / / 47.93.6.5:3306 / magic - API username: rootCopy 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 http://127.0.0.1:9999/magic/web * * * * open magic – API visual interface, see the following interface.

Create a group that is prefixed with a set of API access roots, equivalent to the @Controller(“/order”) annotation.

The interface order_detail is created in the group. The page configudes the basic information of the interface, including interface name, request path, request method, request parameters, request header, etc. The interface directly returns the content

Small rich is the most handsome

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

You can also return JSON data directly

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

import request; a = path.id

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

Magic-api provides some modular components similar to Python development, such as the introduction of import DB module, directly executing SQL statements will return JSON format data, omits a lot of intermediate steps.

Magic-api syntax is not very different from Java, but it is a bit more concise, as long as you have written Java for it is not expensive to learn, such as the common for loop, there are also ordinary and lambda multiple writing.

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.

Magic – API in my whole project in the process of rush can be said to be a great credit, saving more than half of the development time, not only back-end development interface efficiency significantly improved, to the front-end joint adjustment is also a great help.

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. 【 References 】