Bu sayfa henüz yerel dilinizde mevcut değildir. Daha fazla dil seçeneği eklemek için yoğun bir şekilde çalışıyoruz. Desteğiniz için teşekkür ederiz.

Compute
Elastic Cloud Server
Huawei Cloud Flexus
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Cloud Phone Host
Huawei Cloud EulerOS
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
VPC Endpoint
Cloud Connect
Enterprise Router
Enterprise Switch
Global Accelerator
Management & Governance
Cloud Eye
Identity and Access Management
Cloud Trace Service
Resource Formation Service
Tag Management Service
Log Tank Service
Config
OneAccess
Resource Access Manager
Simple Message Notification
Application Performance Management
Application Operations Management
Organizations
Optimization Advisor
IAM Identity Center
Cloud Operations Center
Resource Governance Center
Migration
Server Migration Service
Object Storage Migration Service
Cloud Data Migration
Migration Center
Cloud Ecosystem
KooGallery
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP Filing
Support Plans
My Credentials
Customer Operation Capabilities
Partner Support Plans
Professional Services
Analytics
MapReduce Service
Data Lake Insight
CloudTable Service
Cloud Search Service
Data Lake Visualization
Data Ingestion Service
GaussDB(DWS)
DataArts Studio
Data Lake Factory
DataArts Lake Formation
IoT
IoT Device Access
Others
Product Pricing Details
System Permissions
Console Quick Start
Common FAQs
Instructions for Associating with a HUAWEI CLOUD Partner
Message Center
Security & Compliance
Security Technologies and Applications
Web Application Firewall
Host Security Service
Cloud Firewall
SecMaster
Anti-DDoS Service
Data Encryption Workshop
Database Security Service
Cloud Bastion Host
Data Security Center
Cloud Certificate Manager
Edge Security
Blockchain
Blockchain Service
Web3 Node Engine Service
Media Services
Media Processing Center
Video On Demand
Live
SparkRTC
MetaStudio
Storage
Object Storage Service
Elastic Volume Service
Cloud Backup and Recovery
Storage Disaster Recovery Service
Scalable File Service Turbo
Scalable File Service
Volume Backup Service
Cloud Server Backup Service
Data Express Service
Dedicated Distributed Storage Service
Containers
Cloud Container Engine
SoftWare Repository for Container
Application Service Mesh
Ubiquitous Cloud Native Service
Cloud Container Instance
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GeminiDB
GaussDB
Distributed Database Middleware
Database and Application Migration UGO
TaurusDB
Middleware
Distributed Cache Service
API Gateway
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
Multi-Site High Availability Service
EventGrid
Dedicated Cloud
Dedicated Computing Cluster
Business Applications
Workspace
ROMA Connect
Message & SMS
Domain Name Service
Edge Data Center Management
Meeting
AI
Face Recognition Service
Graph Engine Service
Content Moderation
Image Recognition
Optical Character Recognition
ModelArts
ImageSearch
Conversational Bot Service
Speech Interaction Service
Huawei HiLens
Video Intelligent Analysis Service
Developer Tools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Content Delivery & Edge Computing
Content Delivery Network
Intelligent EdgeFabric
CloudPond
Intelligent EdgeCloud
Solutions
SAP Cloud
High Performance Computing
Developer Services
ServiceStage
CodeArts
CodeArts PerfTest
CodeArts Req
CodeArts Pipeline
CodeArts Build
CodeArts Deploy
CodeArts Artifact
CodeArts TestPlan
CodeArts Check
CodeArts Repo
Cloud Application Engine
MacroVerse aPaaS
KooMessage
KooPhone
KooDrive

Function API Script Compilation Guide

Updated on 2023-02-28 GMT+08:00

This section describes how to compile the definition script when developing a function API on the custom backend.

A function API encapsulates multiple services into one service by compiling function scripts.

The script of a function API is compiled using JavaScript, which complies with the Java Nashorn standard and supports ECMAScript Edition 5.1. The JavaScript engine runs on the Java virtual machine and can invoke the Java class provided by the custom backend to implement specific functions.

Example 1: Helloworld

Define the execute function as an entry. The content returned by the execute function is used as the response body of the function API.

1
2
3
function execute(data) {
    return "Hello world!"
}

Example 2: Obtaining Request Parameters

The data parameter inputted by the execute function contains request parameters.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
function execute(data) {
    data = JSON.parse(data)
    return {
        "method":data["method"],
        "uri":data["uri"],
        "headers":data["headers"],
        "param":data["param"],
        "body":data["body"],
    }
}

Example 3: Setting Response Parameters

The APIConnectResponse object is returned in the execute function. You can specify the HTTP status code, return header, and body returned by the API.

1
2
3
4
importClass(com.roma.apic.livedata.provider.v1.APIConnectResponse);
function execute(data) {
    return new APIConnectResponse(401, {"X-Type":"Demo"}, "unauthorized", false);
}

In this example, the HTTP status code returned when the function API is called is 401, the response header contains "X-Type: Demo", and the response body is "unauthorized".

Example 4: Invoking the Java Function

In the following example, the Java class is introduced using importClass and the functions in it are called. For details about all Java classes, see APIConnectResponse.

1
2
3
4
5
importClass(com.roma.apic.livedata.common.v1.Md5Utils);
function execute(data) {
    var sourceCode = "Hello world!";
    return Md5Utils.encode(sourceCode);
}

Referencing Public Configuration

  1. Log in to the ROMA Connect console. On the Instances page, click View Console next to a specific instance.
  2. In the navigation pane, choose API Connect > Custom Backend. On the Configurations tab page, click Add Configuration.
  3. In the dialog box displayed, configure related information and click OK.
    Table 1 Public reference configurations

    Parameter

    Description

    Configuration Name

    Enter a configuration name.

    Configuration Type

    Select a configuration type. The value can be Template Variable, Password, or Certificate.

    Integration Application

    Select the integration application to which the configuration belongs.

    Configuration Value

    This parameter is available only when Configuration Type is set to Template variable or Password.

    Enter the template variable or password.

    Confirm Value

    This parameter is available only when Configuration Type is set to Password.

    Enter the password again, which must be the same as the value of Configuration Value.

    Certificate

    This parameter is mandatory only when Configuration Type is set to Certificate.

    Enter the certificate in PEM format.

    Private Key

    This parameter is mandatory only when Configuration Type is set to Certificate.

    Enter the private key of the certificate in PEM format.

    Password

    This parameter is available only when Configuration Type is set to Certificate.

    Enter the password of the certificate private key.

    Confirm Password

    This parameter is mandatory only when Configuration Type is set to Certificate.

    Enter the password of the certificate private key again, which must be the same as the value of Password.

    Description

    Enter a description of the configuration.

  4. Reference the configuration in the Java Script function script.
    If the configuration name is example, the reference format is as follows:
    • Template variable: #{example}
    • Password: CipherUtils.getPlainCipherText("example")
    • Certificate: CipherUtils.getPlainCertificate("example")

Sitemizi ve deneyiminizi iyileştirmek için çerezleri kullanırız. Sitemizde tarama yapmaya devam ederek çerez politikamızı kabul etmiş olursunuz. Daha fazla bilgi edinin

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback