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

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

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

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

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

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

仕様

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

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

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


構造

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

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ライブラリのすべてのタイプとパッケージもホワイトリストに含まれています。

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
  • No labels