Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Removed translated content for 'zh'
Sv translation
languageen
Info

Each extension consists of client-side and server-side part. Client-side means resources, which are living inside client's browser, e.g. HTML, Javascript, CSS, images etc.

Server-side part, API endpoints, are executed on the server and can be called from the outside using HTTP request. 

When to create API endpoint

There are several situations, where you need a specific endpoint for your application:

  • Custom business logic is required
  • Calling 3rd party systems is necessary
  • Client API does not offer desired functions

Specification

An API Endpoint is Groovy/Java class compiled and executed on the server at runtime. It may use 3rd party JAR libraries provided as JAR resource inside the extension.

On the source code level, it's possible to use variety of classes and methods, including access to basic BellaDati objects and data - Data sets, Reports, Machine Learning.

API Endpoint is exposed to the outter world using HTTP server and is accepting HTTP GET, POST, DELETE and PUT requests.

Endpoint URL
http://belladati_host/extension/detail:endpoint/EXT_ID/ENDPOINT_NAME
http://belladati_host/ext/detail?id=EXT_ID&action=ENDPOINT_NAME


Structure

API Endpoint a class written is Groovy/Java and overriding doGet(), doPost(), doPut() and doDelete() methods. 

Code Block
languagegroovy
linenumberstrue
package com.belladati;
import com.belladati.extension.BaseExtensionEndpoint;
import org.apache.tapestry5.StreamResponse;
public class MyEndpoint extends BaseExtensionEndpoint {
	@Override
	public StreamResponse doGet() {
		String text = "GET method called with parameter: " + getParameter("say")
		return createStreamResponse(text, "text/plain", 200)
	}
	@Override
	public StreamResponse doPost() {
		String text = "POST method called with parameter: " + getParameter("say")
		return createStreamResponse(text, "text/plain", 200)
	}
}

Types whitelist

Beside types and packages below, all types and packages from provided JAR library are on white list too.

Code Block
languagejava
DecimalFormat.class, NumberFormat.class, LocalDate.class, LocalTime.class, DateTime.class, Arrays.class, ArrayUtils.class, SystemOutputInterceptor.class, Integer.class, Long.class, Double.class, Float.class, BigDecimal.class, String.class, StringUtils.class, JSON.class, JSONObject.class, JSONArray.class, Filter.class, OperationType.class, Map.class
Package name
java.util
java.util.regex
org.apache.commons.logging
com.belladati.json
Sv translation
languageja


Info

各拡張機能は、クライアント側サーバー側の部分で構成されています。クライアント側とは、クライアントのブラウザ内に存在するリソースを意味します。 HTML、Javascript、CSS、画像など。

サーバー側の部分であるAPIエンドポイントはサーバー上で実行され、HTTPリクエストを使用して外部から呼び出すことができます。

APIエンドポイントを作成するタイミング

アプリケーションに特定のエンドポイントが必要な状況はいくつかあります:

クライアントAPIが目的の機能を提供しない

  • カスタムビジネスロジックが必要とされる場合
  • サードパーティのシステムを呼び出す必要がある場合
  • Client APIが目的の機能を提供しない場合

仕様

APIエンドポイントは、実行時にサーバー上でコンパイルおよび実行されるGroovy/Javaクラスです。拡張機能内のJARリソースとして提供されるサードパーティのJARライブラリを使用する場合があります。

ソースコードレベルでは、基本的なBellaDatiオブジェクトとデータ (データセット、レポート、機械学習) へのアクセスなど、様々なクラスとメソッドを使用できます。

APIエンドポイントは、HTTPサーバーを使用して外部に公開され、HTTP GET、POST、DELETE、およびPUTリクエストを受け入れます。


構造

記述されたクラスのAPIエンドポイントはGroovy/Javaであり、doGet(), doPost(), doPut() and doDelete() メソッドをオーバーライドします。

Code Block
languagegroovy
linenumberstrue
package com.belladati;
import com.belladati.extension.BaseExtensionEndpoint;
import org.apache.tapestry5.StreamResponse;
public class MyEndpoint extends BaseExtensionEndpoint {
	@Override
	public StreamResponse doGet() {
		String text = "GET method called with parameter: " + getParameter("say")
		return createStreamResponse(text, "text/plain", 200)
	}
	@Override
	public StreamResponse doPost() {
		String text = "POST method called with parameter: " + getParameter("say")
		return createStreamResponse(text, "text/plain", 200)
	}
}

ホワイトリストのタイプ

以下のタイプとパッケージに加えて、提供されているJARライブラリのすべてのタイプとパッケージもホワイトリストに含まれています。

Code Block
languagejava
DecimalFormat.class, NumberFormat.class, LocalDate.class, LocalTime.class, DateTime.class, Arrays.class, ArrayUtils.class, SystemOutputInterceptor.class, Integer.class, Long.class, Double.class, Float.class, BigDecimal.class, String.class, StringUtils.class, JSON.class, JSONObject.class, JSONArray.class, Filter.class, OperationType.class, Map.class


パッケージ名
java.util
java.util.regex
org.apache.commons.logging
com.belladati.json