APIJSON No-Code ORM

repository·master·Indexed 12 days ago

https://github.com/tencent/apijson

A JSON-based internet communication protocol and no-code ORM that automates API and documentation generation from databases. It enables frontend developers to define custom JSON structures via queries, reducing backend repetitive coding. Supports multiple databases (MySQL, PostgreSQL, MongoDB, etc.) and languages including Java, Go, C#, PHP, Node.js, Python, and Rust. Includes the APIJSONORM library (v8.1.8) and a vast ecosystem of plugins for serialization and database integration.

Tokens
21K
Snippets
58
Records
96
Agent score
93%

What's inside APIJSON

  1. What is APIJSON?

    master

    APIJSON is a JSON-based internet communication protocol and an ORM (Object-Relational Mapping) library designed to simplify backend API development.

    It allows developers to:

    • Get data quickly: Define specific information requirements in a single request to fetch different types of data, reducing the need for multiple endpoints.
    • Simplify API Design: Reduces the workload for backend developers by automating much of the API design and documentation process. This minimizes communication errors between server and client developers and helps maintain compatibility with legacy applications.
    • Perform CRUD operations: Supports Create, Read, Update, and Delete operations, as well as Fuzzy Search and Remote Function Calls.
  2. Overview of APIJSON

    master

    APIJSON is a real-time, no-code, powerful, and secure ORM (Object-Relational Mapping) designed to bridge the gap between backend and frontend development.

    Key Value Proposition:

    • Backend: Provides APIs and documentation automatically without manual coding.
    • Frontend: Can customize response JSON structures directly, reducing the need for backend changes when UI requirements evolve.

    It supports a vast ecosystem of databases (MySQL, PostgreSQL, Oracle, MongoDB, etc.) and multiple programming languages (Java, Go, C#, PHP, Node.js, Python, Rust, etc.).

  3. Explore the APIJSON Ecosystem

    master

    APIJSON has a vast ecosystem of plugins, language bindings, and demo projects. Developers can extend APIJSON's capabilities using specialized plugins for different databases, serialization formats, and frameworks, or use existing language-specific implementations to integrate APIJSON into their tech stacks.

    Key Ecosystem Categories:

    • Language Bindings & Frameworks: Support for Go (apijson-go), PHP (apijson-hyperf, APIJSON-php), Node.js (apijson-node, nestjs-apijson), Python (uliweb-apijson), Rust (apijson-rust), C# (APIJSON.NET), and more.
    • Database Plugins: Specialized support for NoSQL (apijson-mongodb, apijson-cassandra), Time-series (apijson-influxdb), Vector databases (apijson-milvus), and more.
    • Serialization Plugins: Support for various JSON processing libraries like apijson-jackson, apijson-fastjson2, and apijson-gson.
    • Core Utilities:
      • apijson-orm: ORM library for Maven, Gradle, etc.
      • apijson-framework: Server framework for role access and argument validation.
      • apijson-router: Router plugin to expose RESTful-like HTTP APIs.
      • apijson-builder: JavaScript/TypeScript client libraries for constructing APIJSON queries.
    • Testing & Automation Tools: Tools like APIAuto (HTTP API testing), CVAuto (Computer Vision testing), UnitAuto (Unit testing), and SQLAuto (SQL testing).
  4. Explore APIJSON features and demonstrations

    master

    APIJSON provides various resources to understand its capabilities:

    • Features: Understand the specific benefits for both Frontend and Backend developers.
    • Interface Demonstrations: See how APIJSON works in practice using tools like Postman and APIAuto.
    • App Demo: View a live demonstration of the APIJSON client app.
    • Presentations: Access shared talks and presentations about APIJSON.

    Refer to the README for direct links to these demonstrations and feature breakdowns.

  5. Explore APIJSON ecosystem and language implementations

    master

    APIJSON is available across multiple programming languages and frameworks. Depending on your stack, you can use the following implementations:

    • NestJS: nestjs-apijson (supports CRUD, JOIN, and various conditions for MySQL, PostgreSQL, SQLite).
    • Python: uliweb-apijson (supports MySQL, PostgreSQL, SQL Server, Oracle, SQLite, etc.).
    • Rust: apijson-rust (high-performance multi-datasource management for MySQL and PostgreSQL).
    • Go: apijson-go-demo (provides various complexity scenarios) and apijson-go-ui (for UI configuration and permission management).
    • Java/Spring: Various implementations including apijson-spring-boot (uses YAML for simplified configuration) and apijson-template (uses Gradle).
    • JavaScript/TypeScript: apijson-builder (a library to help construct RESTful requests for APIJSON).
  6. APIJSON Protocol Overview

    master

    APIJSON is a JSON transmission protocol that is independent of specific programming languages like C#, Go, Java, JavaScript, PHP, Python, or TypeScript. The protocol defines how the frontend requests data and how the backend responds using a structured JSON format.

    Key Protocol Rules:

    • Use key~ for matching (replaces the deprecated key?).
    • When using SQL functions in @column, use a semicolon ; to separate them instead of a comma (e.g., @column: "store_id;sum(amt):totAmt").
    • The protocol focuses on describing data requirements (which fields, which relations, which filters) within the JSON request itself.
  7. Use APIJSON client libraries

    master

    To simplify interacting with APIJSON from a frontend or client-side application, you can use client libraries that provide RESTful-like functions, avoiding the need to manually construct complex query JSON objects.

    • apijson-builder (JavaScript): A client library providing RESTful-like functions for APIJSON.
    • apijson-builder (TypeScript): A simplified TypeScript wrapper that makes constructing queries easier than direct JSON construction.
  8. How to customize business logic with Remote Functions

    master

    To implement custom business logic that goes beyond standard CRUD operations, you can write Remote Functions in the backend. These functions provide access to the following context to allow for custom data processing:

    • session: The current user session.
    • version: The API version being requested.
    • The current JSON object being processed.
    • Parameter names.

    This allows you to intercept the data returned by the ORM and apply custom transformations or logic before it is sent to the client.

  9. Perform table joins in APIJSON

    master

    APIJSON supports both Application-level joins (@) and SQL-level joins using a join keyword.

    Join Types

    • @ (APP JOIN): Performs an application-layer join. It collects keys from the primary table and uses a single IN clause in SQL to fetch related data from the secondary table, optimizing performance.
    • & (INNER JOIN)
    • < (LEFT JOIN)
    • > (RIGHT JOIN)
    • | (FULL JOIN)
    • ! (OUTER JOIN)
    • * (CROSS JOIN)
    • ^ (SIDE JOIN)
    • ( (ANTI JOIN)
    • ) (FOREIGN JOIN)

    Join Syntax

    String Syntax: "join": "&/Table0,\</Table1/key@"

    Object Syntax: Use an object to define complex relationships, including ON conditions, SELECT columns, GROUP BY, HAVING, and COMBINE logic.

    Example of a LEFT JOIN where ViceTable.key matches MainTable.refKey:

    "MainTable": {},
    "ViceTable": {
      "key@": "/MainTable/refKey"
    }
    {
      "[]": {
        "join": "&/User/id@,</Comment",
        "Moment": {
          "@group": "id"
        },
        "User": {
          "id@": "/Moment/userId"
        },
        "Comment": {
          "momentId@": "/Moment/id"
        }
      }
    }
  10. How logical combinations work with @combine

    master

    The @combine keyword allows you to define complex logical relationships between other keys in the same object. The logic follows a specific precedence:

    1. The expression provided in @combine is evaluated.
    2. Any other keys in the object that are NOT mentioned in @combine are treated as being connected via AND (&) to the result of the @combine expression.

    Example Logic: If you have @combine: "key0 | (key1 & (key2 | !key3))", the final SQL logic is effectively: (OtherKeys) AND (key0 OR (key1 AND (key2 OR (NOT key3))))

  11. Understand APIJSON request methods and HTTP transport

    master

    APIJSON uses specific method naming conventions for different operation types:

    • Operation Types: GETS is the functional equivalent of GET, and HEADS is the functional equivalent of HEAD. While the request syntax differs slightly, the returned results are identical.
    • HTTP Transport: In all HTTP communications, the automated interface methods (get, gets, head, heads, post, put, delete) exclusively use the HTTP POST method for transport.
  12. Perform relational queries and field assignment

    master

    APIJSON allows linking data from different tables/objects using the @ operator. This is used to assign a value from one object to a field in another (e.g., User.id = Moment.userId).

    • Relative Path (id@): Uses a path relative to the current container (e.g., "id@":"Moment/userId").
    • Absolute Path (id@): Uses a full path starting from the root or a specific container (e.g., "momentId@":"[]/Moment/id").
    {
      "Moment":{},
      "User":{
        "id@":"Moment/userId"
      }
    }