使用適用於 SAP ABAP 的 SDK 的 API Gateway 範例 - AWS 適用於 SAP ABAP 的 SDK

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

使用適用於 SAP ABAP 的 SDK 的 API Gateway 範例

下列程式碼範例示範如何使用適用於 SAP ABAP 的 AWS SDK 搭配 API Gateway 來執行動作和實作常見案例。

Actions 是大型程式的程式碼摘錄,必須在內容中執行。雖然動作會告訴您如何呼叫個別服務函數,但您可以在其相關情境中查看內容中的動作。

每個範例均包含完整原始碼的連結,您可在連結中找到如何設定和執行內容中程式碼的相關指示。

主題

動作

以下程式碼範例顯示如何使用 CreateDeployment

適用於 SAP ABAP 的開發套件
注意

GitHub 上提供更多範例。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫中設定和執行。

TRY. oo_result = lo_agw->createdeployment( iv_restapiid = iv_rest_api_id iv_stagename = iv_stage_name iv_description = 'Deployment created by ABAP SDK' ). DATA(lv_deployment_id) = oo_result->get_id( ). MESSAGE 'Deployment created with ID: ' && lv_deployment_id TYPE 'I'. CATCH /aws1/cx_agwbadrequestex INTO DATA(lo_bad_request). MESSAGE lo_bad_request->get_text( ) TYPE 'I'. RAISE EXCEPTION lo_bad_request. CATCH /aws1/cx_agwnotfoundexception INTO DATA(lo_not_found). MESSAGE lo_not_found->get_text( ) TYPE 'I'. RAISE EXCEPTION lo_not_found. CATCH /aws1/cx_agwtoomanyrequestsex INTO DATA(lo_too_many). MESSAGE lo_too_many->get_text( ) TYPE 'I'. RAISE EXCEPTION lo_too_many. ENDTRY.
  • 如需 API 詳細資訊,請參閱《適用於 AWS SAP ABAP 的 SDK API 參考》中的 CreateDeployment

以下程式碼範例顯示如何使用 CreateResource

適用於 SAP ABAP 的開發套件
注意

GitHub 上提供更多範例。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫中設定和執行。

TRY. oo_result = lo_agw->createresource( iv_restapiid = iv_rest_api_id iv_parentid = iv_parent_id iv_pathpart = iv_resource_path ). DATA(lv_resource_id) = oo_result->get_id( ). MESSAGE 'Resource created with ID: ' && lv_resource_id TYPE 'I'. CATCH /aws1/cx_agwbadrequestex INTO DATA(lo_bad_request). MESSAGE lo_bad_request->get_text( ) TYPE 'I'. RAISE EXCEPTION lo_bad_request. CATCH /aws1/cx_agwnotfoundexception INTO DATA(lo_not_found). MESSAGE lo_not_found->get_text( ) TYPE 'I'. RAISE EXCEPTION lo_not_found. CATCH /aws1/cx_agwtoomanyrequestsex INTO DATA(lo_too_many). MESSAGE lo_too_many->get_text( ) TYPE 'I'. RAISE EXCEPTION lo_too_many. ENDTRY.
  • 如需 API 詳細資訊,請參閱《適用於 AWS SAP ABAP 的 SDK API 參考》中的 CreateResource

以下程式碼範例顯示如何使用 CreateRestApi

適用於 SAP ABAP 的開發套件
注意

GitHub 上提供更多範例。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫中設定和執行。

TRY. oo_result = lo_agw->createrestapi( iv_name = iv_api_name iv_description = 'Sample REST API created by ABAP SDK' ). DATA(lv_api_id) = oo_result->get_id( ). MESSAGE 'REST API created with ID: ' && lv_api_id TYPE 'I'. CATCH /aws1/cx_agwbadrequestex INTO DATA(lo_bad_request). MESSAGE lo_bad_request->get_text( ) TYPE 'I'. RAISE EXCEPTION lo_bad_request. CATCH /aws1/cx_agwtoomanyrequestsex INTO DATA(lo_too_many). MESSAGE lo_too_many->get_text( ) TYPE 'I'. RAISE EXCEPTION lo_too_many. CATCH /aws1/cx_agwunauthorizedex INTO DATA(lo_unauthorized). MESSAGE lo_unauthorized->get_text( ) TYPE 'I'. RAISE EXCEPTION lo_unauthorized. ENDTRY.
  • 如需 API 詳細資訊,請參閱《適用於 AWS SAP ABAP 的 SDK API 參考》中的 CreateRestApi

以下程式碼範例顯示如何使用 DeleteRestApi

適用於 SAP ABAP 的開發套件
注意

GitHub 上提供更多範例。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫中設定和執行。

TRY. lo_agw->deleterestapi( iv_restapiid = iv_rest_api_id ). MESSAGE 'REST API deleted successfully' TYPE 'I'. CATCH /aws1/cx_agwbadrequestex INTO DATA(lo_bad_request). MESSAGE lo_bad_request->get_text( ) TYPE 'I'. RAISE EXCEPTION lo_bad_request. CATCH /aws1/cx_agwnotfoundexception INTO DATA(lo_not_found). MESSAGE lo_not_found->get_text( ) TYPE 'I'. RAISE EXCEPTION lo_not_found. CATCH /aws1/cx_agwtoomanyrequestsex INTO DATA(lo_too_many). MESSAGE lo_too_many->get_text( ) TYPE 'I'. RAISE EXCEPTION lo_too_many. ENDTRY.
  • 如需 API 詳細資訊,請參閱《適用於 AWS SAP ABAP 的 SDK API 參考》中的 DeleteRestApi

以下程式碼範例顯示如何使用 GetResources

適用於 SAP ABAP 的開發套件
注意

GitHub 上提供更多範例。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫中設定和執行。

TRY. oo_result = lo_agw->getresources( iv_restapiid = iv_rest_api_id ). DATA(lt_resources) = oo_result->get_items( ). DATA(lv_count) = lines( lt_resources ). MESSAGE 'Found ' && lv_count && ' resources' TYPE 'I'. CATCH /aws1/cx_agwbadrequestex INTO DATA(lo_bad_request). MESSAGE lo_bad_request->get_text( ) TYPE 'I'. RAISE EXCEPTION lo_bad_request. CATCH /aws1/cx_agwnotfoundexception INTO DATA(lo_not_found). MESSAGE lo_not_found->get_text( ) TYPE 'I'. RAISE EXCEPTION lo_not_found. CATCH /aws1/cx_agwtoomanyrequestsex INTO DATA(lo_too_many). MESSAGE lo_too_many->get_text( ) TYPE 'I'. RAISE EXCEPTION lo_too_many. ENDTRY.
  • 如需 API 詳細資訊,請參閱《適用於 AWS SAP ABAP 的 SDK API 參考》中的 GetResources

以下程式碼範例顯示如何使用 GetRestApis

適用於 SAP ABAP 的開發套件
注意

GitHub 上提供更多範例。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫中設定和執行。

TRY. oo_result = lo_agw->getrestapis( ). DATA(lt_apis) = oo_result->get_items( ). DATA(lv_count) = lines( lt_apis ). MESSAGE 'Found ' && lv_count && ' REST APIs' TYPE 'I'. CATCH /aws1/cx_agwbadrequestex INTO DATA(lo_bad_request). MESSAGE lo_bad_request->get_text( ) TYPE 'I'. RAISE EXCEPTION lo_bad_request. CATCH /aws1/cx_agwtoomanyrequestsex INTO DATA(lo_too_many). MESSAGE lo_too_many->get_text( ) TYPE 'I'. RAISE EXCEPTION lo_too_many. ENDTRY.
  • 如需 API 詳細資訊,請參閱《適用於 AWS SAP ABAP 的 SDK API 參考》中的 GetRestApis

以下程式碼範例顯示如何使用 PutIntegration

適用於 SAP ABAP 的開發套件
注意

GitHub 上提供更多範例。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫中設定和執行。

TRY. oo_result = lo_agw->putintegration( iv_restapiid = iv_rest_api_id iv_resourceid = iv_resource_id iv_httpmethod = iv_http_method iv_type = 'AWS_PROXY' iv_integrationhttpmethod = 'POST' iv_uri = iv_integration_uri ). MESSAGE 'Integration configured for method' TYPE 'I'. CATCH /aws1/cx_agwbadrequestex INTO DATA(lo_bad_request). MESSAGE lo_bad_request->get_text( ) TYPE 'I'. RAISE EXCEPTION lo_bad_request. CATCH /aws1/cx_agwnotfoundexception INTO DATA(lo_not_found). MESSAGE lo_not_found->get_text( ) TYPE 'I'. RAISE EXCEPTION lo_not_found. CATCH /aws1/cx_agwtoomanyrequestsex INTO DATA(lo_too_many). MESSAGE lo_too_many->get_text( ) TYPE 'I'. RAISE EXCEPTION lo_too_many. ENDTRY.
  • 如需 API 詳細資訊,請參閱《適用於 AWS SAP ABAP 的 SDK API 參考》中的 PutIntegration

以下程式碼範例顯示如何使用 PutIntegrationResponse

適用於 SAP ABAP 的開發套件
注意

GitHub 上提供更多範例。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫中設定和執行。

TRY. oo_result = lo_agw->putintegrationresponse( iv_restapiid = iv_rest_api_id iv_resourceid = iv_resource_id iv_httpmethod = iv_http_method iv_statuscode = '200' ). MESSAGE 'Integration response configured for status 200' TYPE 'I'. CATCH /aws1/cx_agwbadrequestex INTO DATA(lo_bad_request). MESSAGE lo_bad_request->get_text( ) TYPE 'I'. RAISE EXCEPTION lo_bad_request. CATCH /aws1/cx_agwnotfoundexception INTO DATA(lo_not_found). MESSAGE lo_not_found->get_text( ) TYPE 'I'. RAISE EXCEPTION lo_not_found. CATCH /aws1/cx_agwtoomanyrequestsex INTO DATA(lo_too_many). MESSAGE lo_too_many->get_text( ) TYPE 'I'. RAISE EXCEPTION lo_too_many. ENDTRY.
  • 如需 API 詳細資訊,請參閱《適用於 AWS SAP ABAP 的 SDK API 參考》中的 PutIntegrationResponse

以下程式碼範例顯示如何使用 PutMethod

適用於 SAP ABAP 的開發套件
注意

GitHub 上提供更多範例。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫中設定和執行。

TRY. oo_result = lo_agw->putmethod( iv_restapiid = iv_rest_api_id iv_resourceid = iv_resource_id iv_httpmethod = iv_http_method iv_authorizationtype = 'NONE' ). MESSAGE 'Method ' && iv_http_method && ' added to resource' TYPE 'I'. CATCH /aws1/cx_agwbadrequestex INTO DATA(lo_bad_request). MESSAGE lo_bad_request->get_text( ) TYPE 'I'. RAISE EXCEPTION lo_bad_request. CATCH /aws1/cx_agwnotfoundexception INTO DATA(lo_not_found). MESSAGE lo_not_found->get_text( ) TYPE 'I'. RAISE EXCEPTION lo_not_found. CATCH /aws1/cx_agwtoomanyrequestsex INTO DATA(lo_too_many). MESSAGE lo_too_many->get_text( ) TYPE 'I'. RAISE EXCEPTION lo_too_many. ENDTRY.
  • 如需 API 詳細資訊,請參閱《適用於 AWS SAP ABAP 的 SDK API 參考》中的 PutMethod

以下程式碼範例顯示如何使用 PutMethodResponse

適用於 SAP ABAP 的開發套件
注意

GitHub 上提供更多範例。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫中設定和執行。

TRY. oo_result = lo_agw->putmethodresponse( iv_restapiid = iv_rest_api_id iv_resourceid = iv_resource_id iv_httpmethod = iv_http_method iv_statuscode = '200' ). MESSAGE 'Method response configured for status 200' TYPE 'I'. CATCH /aws1/cx_agwbadrequestex INTO DATA(lo_bad_request). MESSAGE lo_bad_request->get_text( ) TYPE 'I'. RAISE EXCEPTION lo_bad_request. CATCH /aws1/cx_agwnotfoundexception INTO DATA(lo_not_found). MESSAGE lo_not_found->get_text( ) TYPE 'I'. RAISE EXCEPTION lo_not_found. CATCH /aws1/cx_agwtoomanyrequestsex INTO DATA(lo_too_many). MESSAGE lo_too_many->get_text( ) TYPE 'I'. RAISE EXCEPTION lo_too_many. ENDTRY.
  • 如需 API 詳細資訊,請參閱《適用於 AWS SAP ABAP 的 SDK API 參考》中的 PutMethodResponse