使用适用于 SAP 的 SDK 的 API Gateway 示例 - AWS 适用于 SAP 的 SDK ABA

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

使用适用于 SAP 的 SDK 的 API Gateway 示例

以下代码示例向您展示了如何使用适用于 SAP ABAP 的 AWS 软件开发工具包和 API Gateway 来执行操作和实现常见场景。

操作是大型程序的代码摘录,必须在上下文中运行。您可以通过操作了解如何调用单个服务函数,还可以通过函数相关场景的上下文查看操作。

每个示例都包含一个指向完整源代码的链接,您可以从中找到有关如何在上下文中设置和运行代码的说明。

主题

操作

以下代码示例演示了如何使用 CreateDeployment

适用于 SAP ABAP 的 SDK
注意

还有更多相关信息 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 的详细信息,请参阅适用CreateDeployment于 S AP 的AWS SDK ABAP API 参考

以下代码示例演示了如何使用 CreateResource

适用于 SAP ABAP 的 SDK
注意

还有更多相关信息 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 的详细信息,请参阅适用CreateResource于 S AP 的AWS SDK ABAP API 参考

以下代码示例演示了如何使用 CreateRestApi

适用于 SAP ABAP 的 SDK
注意

还有更多相关信息 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 的详细信息,请参阅适用CreateRestApi于 S AP 的AWS SDK ABAP API 参考

以下代码示例演示了如何使用 DeleteRestApi

适用于 SAP ABAP 的 SDK
注意

还有更多相关信息 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 的详细信息,请参阅适用DeleteRestApi于 S AP 的AWS SDK ABAP API 参考

以下代码示例演示了如何使用 GetResources

适用于 SAP ABAP 的 SDK
注意

还有更多相关信息 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 的详细信息,请参阅适用GetResources于 S AP 的AWS SDK ABAP API 参考

以下代码示例演示了如何使用 GetRestApis

适用于 SAP ABAP 的 SDK
注意

还有更多相关信息 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 的详细信息,请参阅适用GetRestApis于 S AP 的AWS SDK ABAP API 参考

以下代码示例演示了如何使用 PutIntegration

适用于 SAP ABAP 的 SDK
注意

还有更多相关信息 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 的详细信息,请参阅适用PutIntegration于 S AP 的AWS SDK ABAP API 参考

以下代码示例演示了如何使用 PutIntegrationResponse

适用于 SAP ABAP 的 SDK
注意

还有更多相关信息 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.

以下代码示例演示了如何使用 PutMethod

适用于 SAP ABAP 的 SDK
注意

还有更多相关信息 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 的详细信息,请参阅适用PutMethod于 S AP 的AWS SDK ABAP API 参考

以下代码示例演示了如何使用 PutMethodResponse

适用于 SAP ABAP 的 SDK
注意

还有更多相关信息 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 的详细信息,请参阅适用PutMethodResponse于 S AP 的AWS SDK ABAP API 参考