magic-api Documentation
repository·master·Indexed 23 days ago
https://github.com/ssssssss-team/magic-apiA rapid interface development framework for Java that enables building and managing HTTP APIs via a web UI, eliminating the need for traditional boilerplate like Controllers and Mappers. It supports JDBC-compliant databases, NoSQL (Redis, MongoDB), and features a dynamic compilation engine via magic-script for real-time changes. The framework includes support for Spring Boot integration, cluster deployment, Swagger generation, and a Nebula graph plugin for executing NGSL queries.
What's inside magic-api
- magic-api is a Java-based rapid interface development framework. It allows developers to create HTTP APIs through a web-based UI, automatically mapping them to HTTP endpoints. This eliminates the need to manually define traditional Java boilerplate such as Controllers, Services, Daos, Mappers, XML files, or VO objects.
Key features of magic-api
mastermagic-api provides a wide range of capabilities for rapid API development:
- Database Support: Supports JDBC-compliant databases (MySQL, MariaDB, Oracle, DB2, PostgreSQL, SQLServer) and NoSQL (Redis, MongoDB).
- Dynamic Development: Uses the
magic-scriptengine for dynamic compilation. Changes are applied in real-time without requiring a server restart. - Advanced Querying: Supports Linq-style queries, database transactions, SQL concatenation, placeholders, and conditional syntax.
- Management & DevOps: Supports cluster deployment with automatic interface synchronization, script version history comparison/recovery, and Swagger documentation generation.
- Extensibility: Allows importing Spring Beans and Java classes, and supports custom utility classes, modules, type extensions, dialects, and column name conversions.
- Developer Experience: Features include code completion, parameter hints, error highlighting, online debugging, and file upload/download capabilities.
Add magic-api to a Spring Boot project via Maven
masterTo use magic-api in a Spring Boot application, include the
magic-api-spring-boot-starterdependency in yourpom.xmlfile.<!-- 以spring-boot-starter的方式引用 --> <dependency> <groupId>org.ssssssss</groupId> <artifactId>magic-api-spring-boot-starter</artifactId> <version>2.2.2</version> </dependency>Configure database tables for magic-api v0.7.x+
masterFor versions 0.7.x and later, magic-api requires two specific tables to manage files and backup records. You must execute the following SQL statements to set up the schema in your database.
-- File storage table CREATE TABLE `magic_api_file_v2` ( `file_path` varchar(512) NOT NULL, `file_content` mediumtext, PRIMARY KEY (`file_path`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; -- Backup record table CREATE TABLE `magic_backup_record_v2` ( `id` varchar(32) NOT NULL COMMENT '原对象ID', `create_date` bigint(13) NOT NULL COMMENT '备份时间', `tag` varchar(32) DEFAULT NULL COMMENT '标签', `type` varchar(32) DEFAULT NULL COMMENT '类型', `name` varchar(64) DEFAULT NULL COMMENT '原名称', `content` blob COMMENT '备份内容', `create_by` varchar(64) DEFAULT NULL COMMENT '操作人', PRIMARY KEY (`id`,`create_date`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;Install the Nebula plugin
masterTo use Nebula graph capabilities within magic-api, add the
magic-api-plugin-nebuladependency to your Mavenpom.xmlfile. Replacemagic-api-lastest-versionwith the actual latest version of magic-api.<dependency> <groupId>org.ssssssss</groupId> <artifactId>magic-api-plugin-nebula</artifactId> <version>magic-api-lastest-version</version> </dependency>Access the magic-api online editor
masterOnce the application is running with the configuredmagic-api.webpath, you can access the online editor to develop and manage your APIs by navigating to the configured URL in your browser (e.g.,http://localhost:9999/magic/web).Configure the Nebula plugin
masterConfigure the connection details for your Nebula graph instance in your application's YAML configuration file using the
nebulaprefix. You can use environment variables for sensitive information.Available keys:
hostAddress: The host and port of the Nebula server (defaults tolocalhost:9669).userName: The username for authentication (defaults toroot).password: The password for authentication (defaults tonebula).
nebula: hostAddress: ${NEBULA_HOSTADDRESS:localhost:9669} userName: ${NEBULA_USERNAME:root} password: ${NEBULA_PASSWORD:nebula}Configure magic-api in application.properties
masterAfter adding the dependency, configure the following properties in your
application.propertiesfile:magic-api.web: Defines the URL path for the web-based management interface.magic-api.resource.location: Defines where the configuration files are stored. Note: If the path starts withclasspath:, the mode is read-only.
server.port=9999 #配置web页面入口 magic-api.web=/magic/web #配置文件存储位置。当以classpath开头时,为只读模式 magic-api.resource.location=/data/magic-apiExecute Nebula queries in magic-api
masterYou can interact with Nebula using the
nebulamodule imported in your magic-api scripts.Key methods:
nebula.executeJson(ngsl): Executes a Nebula Graph Language (NGSL) query and returns the result as a JSON object. Usenebula.convert(resultJson)to format the output.nebula.executeNebulaModel(ngsl): Executes a query specifically designed to return a graph model structure.
For a full list of available methods, refer to the source class
org.ssssssss.magicapi.nebula.NebulaModule.import nebula; var ngsl = """ USE db_name;MATCH p_=(p:`assignee`)-[*3]-(p2:`transferor`) where id(p2) == "阿里巴巴" or id(p)== "阿里巴巴" RETURN p_ limit 1000' """ var resultJson = nebula.executeJson(ngsl) nebula.convert(resultJson) nebula.executeNebulaModel(ngsl)Nebula query response data format
masterThe Nebula plugin returns data in a structured format containing
nodesandedges, which is compatible with many frontend graph visualization libraries like AntV G6.{ "code": 0, "message": "success", "data": { "nodes": [ { "edgeSize": 1, "assignee.name": "中航纽赫融资租赁(上海)有限公司", "type": "vertex", "assignee.addr": "上海市中国(上海)自由贸易试验区正定路530号A5库区集中辅助区三层318室", "assignee.legal_person": "周勇", "assignee.type": "企业", "id": "中航纽赫融资租赁(上海)有限公司" } ], "edges": [ { "dst": "陕西海富融资租赁有限公司", "src": "中航纽赫融资租赁(上海)有限公司", "label": "trans_with", "type": "edge", "target": "陕西海富融资租赁有限公司" } ] }, "timestamp": 1692149280167, "requestTime": 1692149280143, "executeTime": 24 }