このエントリは以下のエントリをベースにしています。
This entry is based on the following one written by Michal Karm Babacek (Red Hat).
https://microprofile.io/2019/07/08/command-line-interface-for-microprofile-starter-is-available-now/
2019年2月から利用可能のMicroProfile Starterサービスですが、REST APIとCLIからも利用できるようになりました。
Eclipse MicroProfile Starter (Beta) Available
https://microprofile.io/2019/02/06/eclipse-microprofile-starter-beta-available/
https://logico-jp.io/2019/02/10/eclipse-microprofile-starter-beta-available/
これはMicroProfile Starterの開始以来、Starterにコマンドラインでアクセスできるように、MicroProfile開発者から要求されてきた機能です。このAPIは、今後予定されているVisual Studio Codeの拡張や、Eclipse Che、IntelliJ IDEA、Netbeansの拡張でも使用される予定です。
Why do you need this API?
- CLI : 開発者がcURLやPowerShellを使ってアプリケーションを生成できます。Webブラウザを開く必要はありません。
- Tools integration : MicroProfileアプリケーション生成機能を統合開発環境やツールに統合するためのサービスを他社に提供します。
How to use the MicroProfile Starter CLI
一番簡単なプロジェクト生成方法は、サーバを選択し、すべての仕様がデフォルトで有効になっている最新のMicroProfileバージョンをサービスに選択することです。
$ curl -O -J 'https://start.microprofile.io/api/project?supportedServer=THORNTAIL_V2'
curl: Saved to filename 'demo.zip'
Shell session recording
cURLの例をテキストとして記録しました。動画から直接コピー&ペーストできます。利用可能な選択肢の並び方やサーバや仕様の選択方法がわかる動画になっています。
$ curl -O -J 'https://start.microprofile.io/api/project?supportedServer=PAYARA_MICRO&selectedSpecs=JWT_AUTH&selectedSpecs=METRICS'
Windows PowerShell session
以下の動画では、PowerShellを使ってMicroProfileプロジェクトを生成する方法を紹介しています。
Invoke-WebRequest -OutFile project.zip -Uri https://start.microprofile.io/api/project?supportedServer=TOMEE
Expand-Archive ./project.zip
Noteworthy resources for selecting other servers and specifications are:
$ curl https://start.microprofile.io/api/mpVersion
$ curl https://start.microprofile.io/api/mpVersion/MP22
Documentation
最新のドキュメントやサンプルはプロジェクトリポジトリのREST-README.mdにあります。以下のように、コマンドラインからアクセスすることもできます。
$ curl https://start.microprofile.io/api/
Project generator REST API
https://github.com/eclipse/microprofile-starter/blob/master/src/main/resources/REST-README.md
さらに、正式な仕様がSwaggerHubでご覧頂けます。APIバージョンが指定されていない場合、最新のバージョンをデフォルトで選択します。例えば、start.microprofile.io/api/ は start.microprofile.io/api/1/ に相当します。WindowsユーザーにはcURL for WindowsやPowerShellを含め、多数の選択肢があります。
MicroProfile Starter – Project generator API
https://app.swaggerhub.com/apis-docs/microprofile/starter/1
Advanced usage
このAPIを使うと、JSONファイルをPOSTできます。cURLコマンドにクエリパラメータを渡す必要はありません。また、コード内でEtagレスポンスヘッダとIf-Node-Matchリクエストヘッダを使うことができます。これにより、同じZipファイルや同じJSONレスポンスの解析を何度も実行することがなくなります。
RFC7232 Hypertext Transfer Protocol (HTTP/1.1): Conditional Requests
Etag
https://tools.ietf.org/html/rfc7232#section-2.3
If-None-Match
https://tools.ietf.org/html/rfc7232#section-3.2
EtagとIf-Node-Matchの利用方法ならびにJSONのPOSTの例はドキュメントに記載があります。
EtagとIf-Node-Matchの例
https://github.com/eclipse/microprofile-starter/blob/master/src/main/resources/REST-README.md#examples
Use JSON for get the project
https://github.com/eclipse/microprofile-starter/blob/master/src/main/resources/REST-README.md#use-json-for-get-the-project
大事なことを言い忘れていましたが、このAPIはツールやIDEと統合しやすいリソースを提供します。これらのリソースは、大きなJSONとして1つのHTTPレスポンスとして、有効なオプションのマトリックス全体を返します。
Integration with IDEs
https://github.com/eclipse/microprofile-starter/blob/master/src/main/resources/REST-README.md#integration-with-ides
Call to action
まもなく登場するMicroProfile Starter用VSCode extensionにご注目ください。さらに、MicroProfileコミュニティーでは、Eclipse Che、IntelliJ IDEA、Netbeansなど、他のIDE用のextensionの設計と実装のためのボランティアも募集しています。IntelliJのextensionをやってみたいという方はissue #170、Eclipse Cheのextensionをやってみたいという方はissue #171、Netbeansのextensionをやってみたいという方はissue #174にそれぞれコメントしてください。
Create Intellij extension for MP Starter #170
https://github.com/eclipse/microprofile-starter/issues/170
Create MP extension for Eclipse Che #171
https://github.com/eclipse/microprofile-starter/issues/171
Create MP extension for NetBean IDE #174
https://github.com/eclipse/microprofile-starter/issues/174