Skip to content

Java OpenSDK Overview

What is it?

The Lovrabet Java OpenSDK is a lightweight Java client library for accessing the OpenAPI services of the Lovrabet platform from Java applications.

With this SDK, your Java backend can easily:

  • 📊 Read data — fetch business data from the Lovrabet platform
  • ✏️ Write data — create and update your business records
  • 🔐 Secure access — signature authentication handled automatically, keeping your data safe
  • 🚀 Fast integration — connect in just a few lines of code

What problems does it solve?

Scenario 1: Integrate Lovrabet data into an existing Java system

Problem: You manage business data — customers, orders, sales pipelines — on the Lovrabet platform, and now you need that data in your own Java backend.

With the OpenSDK:

Java
// 在您的 Spring Boot 应用中
@Service
public class CustomerService {
    private final LovrabetSDKClient sdkClient;

    public List<Customer> getSalesLeads() {
        LovrabetRequest request = new LovrabetRequest();
        request.setAppCode("app-xxx");
        request.setModelCode("customer-dataset");

        // 获取销售线索数据
        LovrabetResult<?> result = sdkClient.getList(request);

        if (result.isSuccess()) {
            return parseCustomers(result.getData());
        }
        return Collections.emptyList();
    }
}

Value:

  • ✅ No manual HTTP or signature logic to manage
  • ✅ Type-safe API calls
  • ✅ Unified error handling
  • ✅ Authentication that works out of the box

Scenario 2: Sync data from a Java app to Lovrabet

Problem: Your Java system produces new business data (orders, tickets) that needs to flow into the Lovrabet platform for visualization, analysis, and reporting.

With the OpenSDK:

Java
// 在您的订单服务中
@Service
public class OrderSyncService {
    private final LovrabetSDKClient sdkClient;

    public void syncOrder(Order order) {
        LovrabetRequest request = new LovrabetRequest();
        request.setAppCode("app-xxx");
        request.setModelCode("orders-dataset");

        // 构建订单数据
        Map<String, Object> orderData = new HashMap<>();
        orderData.put("order_no", order.getOrderNo());
        orderData.put("amount", order.getAmount());
        orderData.put("customer_name", order.getCustomerName());
        orderData.put("create_date", order.getCreateDate());
        request.setParamMap(orderData);

        // 创建订单记录
        LovrabetResult<String> result = sdkClient.create(request);

        if (result.isSuccess()) {
            logger.info("订单同步成功: {}", result.getData());
        } else {
            logger.error("订单同步失败: {}", result.getResultMsg());
        }
    }
}

Value:

  • ✅ Real-time data sync
  • ✅ Less manual data importing
  • ✅ A single source of data for cross-system analysis

Scenario 3: Build a data hub in a microservices architecture

Problem: In a microservices architecture, several services need access to the same Lovrabet data, but you don't want every service to integrate with the OpenAPI directly.

With the OpenSDK:

Java
// 构建统一的数据服务
@RestController
@RequestMapping("/api/data")
public class DataGatewayController {
    private final LovrabetSDKClient sdkClient;

    // 为内部微服务提供统一的数据访问接口
    @GetMapping("/customers")
    public ResponseEntity<List<Map<String, Object>>> getCustomers(
        @RequestParam(defaultValue = "1") int page,
        @RequestParam(defaultValue = "20") int size
    ) {
        LovrabetRequest request = new LovrabetRequest();
        request.setAppCode("app-xxx");
        request.setModelCode("customers");

        Map<String, Object> params = new HashMap<>();
        params.put("currentPage", page);
        params.put("pageSize", size);
        request.setParamMap(params);

        LovrabetResult<?> result = sdkClient.getList(request);

        if (result.isSuccess()) {
            return ResponseEntity.ok((List<Map<String, Object>>) result.getData());
        }
        return ResponseEntity.status(500).build();
    }
}

Value:

  • ✅ A unified data access layer
  • ✅ Centrally managed credentials
  • ✅ Lower coupling across services
  • ✅ Access control and auditing support

When to use it

ScenarioFitNotes
✅ Spring Boot backendsRecommendedIntegrates perfectly with the Spring ecosystem
✅ Scheduled tasks / data syncRecommendedBuild reliable data sync services with the OpenSDK
✅ Microservices data hubRecommendedBuild a unified data access layer
✅ Traditional Java web appsSuitableWorks with Servlet, Struts, JSP, and more
⚠️ Direct frontend callsNot recommendedUse the Node.js SDK or a browser SDK instead
⚠️ Android appsNot recommendedUse a dedicated mobile SDK

Core strengths

1. Simple to use

Java
// 只需 3 步即可完成数据查询
LovrabetSDKClient client = new LovrabetSDKClient(accessKey, baseUrl);
LovrabetRequest request = new LovrabetRequest();
request.setAppCode("app-xxx");
LovrabetResult<?> result = client.getDatasetCodeList(request);

2. Safe and reliable

  • Automatic signing — the SDK handles HMAC-SHA256 signing; no manual computation needed
  • Key protection — the AccessKey stays server-side and is never exposed to the frontend
  • HTTPS transport — every request travels over encrypted HTTPS

3. Complete error handling

Java
LovrabetResult<?> result = client.getOne(request);

if (result.isSuccess()) {
    // 成功:处理业务数据
    Object data = result.getData();
} else {
    // 失败:获取错误码和错误信息
    String errorCode = result.getResultCode();
    String errorMsg = result.getResultMsg();
    logger.error("查询失败 [{}]: {}", errorCode, errorMsg);
}

4. Production-grade quality

  • ✅ Thread-safe with high-concurrency support
  • ✅ Consistent response format
  • ✅ Detailed error messages
  • ✅ Retry and timeout controls built in

Quick start

1. Add the dependency

XML
<dependency>
    <groupId>com.lovrabet.runtime</groupId>
    <artifactId>lovrabet-runtime-opensdk</artifactId>
    <version>1.0.0-SNAPSHOT</version>
</dependency>

2. Get your credentials

  1. Sign in to the Lovrabet platform
  2. Open app management and copy your app code (AppCode)
  3. Enable the OpenAPI feature and generate an access key (AccessKey)

3. Write your first program

Java
import com.lovrabet.runtime.opensdk.client.LovrabetSDKClient;
import com.lovrabet.runtime.opensdk.model.LovrabetRequest;
import com.lovrabet.runtime.opensdk.model.LovrabetResult;

public class HelloLovrabet {
    public static void main(String[] args) {
        // 1. 创建客户端
        String accessKey = "ak-your-access-key";
        String baseUrl = "https://runtime.lovrabet.com/openapi";
        LovrabetSDKClient client = new LovrabetSDKClient(accessKey, baseUrl);

        // 2. 构建请求
        LovrabetRequest request = new LovrabetRequest();
        request.setAppCode("app-xxx");

        // 3. 调用 API
        LovrabetResult<?> result = client.getDatasetCodeList(request);

        // 4. 处理结果
        if (result.isSuccess()) {
            System.out.println("数据集列表: " + result.getData());
        } else {
            System.err.println("失败: " + result.getResultMsg());
        }
    }
}

4. Learning path

Work through these topics in order to master the SDK step by step:

  1. 📖 Quick Start — your first CRUD program in 5 minutes
  2. 📚 Core Concepts — how the SDK works under the hood
  3. 📋 API Reference — the complete interface documentation
  4. 💡 Business Examples — five real-world scenarios implemented
  5. 🚀 Best Practices — production optimization tips
  6. ❓ FAQ — answers to common questions

Support

If you run into problems, get help through any of these channels:


Doc version: 1.0.0Last updated: 2025-10-12Applies to: lovrabet-runtime-opensdk 1.0.0+

基于飞书知识库同步生成,内容以飞书源文档为准