├── LICENSE ├── LICENSES └── Apache-2.0.txt ├── README.md ├── REUSE.toml └── src ├── package.devc.xml ├── zaf_cl_rest_petstore_client.clas.abap ├── zaf_cl_rest_petstore_client.clas.locals_imp.abap ├── zaf_cl_rest_petstore_client.clas.testclasses.abap ├── zaf_cl_rest_petstore_client.clas.xml ├── zaf_cl_rest_petstore_model.clas.abap ├── zaf_cl_rest_petstore_model.clas.xml ├── zaf_if_petstore_types.intf.abap └── zaf_if_petstore_types.intf.xml /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /LICENSES/Apache-2.0.txt: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # OData Client proxy samples 2 | 3 | [](https://api.reuse.software/info/github.com/SAP-samples/abap-odata-client-proxy-samples) 4 | 5 | ## Description 6 | 7 | The OData Client proxy allows to consume OData services but also pure REST services programmatically using ABAP. The following sample code can be used to perform more complex requests than the ones that are provided as code snippets within the ABAP Development Tools in Eclipse. 8 | 9 | It also contains a sample for the consumption of a pure REST service. 10 | 11 | ### CP REST sample 12 | 13 | This sample code uses the well-known [Swagger Petstore Sample](https://github.com/swagger-api/swagger-petstore) which can also be found on GitHub. 14 | 15 | It shows how the OData proxy client can be used to also consume pure REST services that are no OData service. 16 | 17 | In the ABAP sample code you will have to replace the constant **petstore_url**. 18 |
CONST: petstore_url type string value ‘19 | with the URL that points to the hosted version that is described in the above mentioned GitHub repository or an instance that you are running on your own. 20 | 21 | ## Requirements 22 | 23 | The ABAP code can be used on: 24 | - SAP BTP, ABAP Environment 25 | - SAP S4HANA Cloud, ABAP Environment 26 | - SAP ABAP Platform 2021 and later 27 | 28 | ## Download and Installation 29 | 30 | 1. Create a package (e.g.) `TEST_CP_REST_SAMPLE` 31 | 2. Start the report `ZABAPGIT` or `ZABAPGIT_STANDALONE` depending on what you have installed in your system 32 | 3. Create an offline repository or an online repository with the package and with the URL of this GitHub repository 33 | 4. Pull changes 34 | 5. Use mass activation to activate the objects that have been imported in step 3 35 | 36 | ## Known Issues 37 | 38 | 39 | ## How to obtain support 40 | [Create an issue](https://github.com/SAP-samples/’ .
Create a Pet
15 | "! @parameter is_pet |typed structure containing create data
16 | "! @parameter rs_pet |typed structure containing response data from server
17 | "! @raising /iwbep/cx_gateway | 18 | METHODS pet_create 19 | IMPORTING 20 | is_pet TYPE zaf_if_petstore_types=>tys_pet 21 | RETURNING 22 | VALUE(rs_pet) TYPE zaf_if_petstore_types=>tys_pet 23 | RAISING 24 | /iwbep/cx_gateway. 25 | 26 | 27 | "!Delete a Pet with supplied id
28 | "! This method does not return a json response body which can be serialized in to abap structure, so the http code is returned. 29 | "! @parameter iv_id | 30 | "! @parameter rv_http_status_code | 31 | "! @raising /iwbep/cx_gateway | 32 | METHODS pet_delete 33 | IMPORTING 34 | iv_id TYPE i 35 | RETURNING 36 | VALUE(rv_http_status_code) TYPE i 37 | RAISING 38 | /iwbep/cx_gateway. 39 | 40 | 41 | "!Get a pet with supplied id
42 | "! 43 | "! @parameter iv_id |The id of the pet
44 | "! @parameter rs_pet |Returned pet as ABAP structure, complete with deep fields.
45 | "! @raising /iwbep/cx_gateway | 46 | METHODS pet_read_by_id 47 | IMPORTING 48 | iv_id TYPE i 49 | RETURNING 50 | VALUE(rs_pet) TYPE zaf_if_petstore_types=>tys_pet 51 | RAISING 52 | /iwbep/cx_gateway. 53 | 54 | 55 | "!Update a pet using PUT
56 | "! @parameter is_pet |typed structure containing update data
57 | "! @parameter rs_pet |typed structure containing response data from server
58 | "! @raising /iwbep/cx_gateway | 59 | METHODS pet_update 60 | IMPORTING 61 | is_pet TYPE zaf_if_petstore_types=>tys_pet 62 | RETURNING 63 | VALUE(rs_pet) TYPE zaf_if_petstore_types=>tys_pet 64 | RAISING 65 | /iwbep/cx_gateway. 66 | 67 | 68 | "!Update the name and status of the pet having the supplied ID
69 | "! The variables to be updated are sent as query parameters. The request type is POST 70 | "! @parameter iv_id |ID of the pet that is to be updated.
71 | "! @parameter iv_name |new name for the pet
72 | "! @parameter iv_status |new status for the pet
73 | "! @parameter rs_pet |Updated pet
74 | "! @raising /iwbep/cx_gateway | 75 | METHODS pet_update_name_and_status 76 | IMPORTING 77 | iv_id TYPE i 78 | iv_name TYPE zaf_if_petstore_types=>tys_pet-name 79 | iv_status TYPE zaf_if_petstore_types=>tys_pet-status 80 | RETURNING 81 | VALUE(rs_pet) TYPE zaf_if_petstore_types=>tys_pet 82 | RAISING 83 | /iwbep/cx_gateway. 84 | 85 | PRIVATE SECTION. 86 | 87 | DATA: mo_client_proxy TYPE REF TO /iwbep/if_cp_client_proxy_rest, 88 | mo_http_client TYPE REF TO if_http_client. 89 | 90 | METHODS create_client_proxy 91 | RETURNING 92 | VALUE(ro_client_proxy) TYPE REF TO /iwbep/if_cp_client_proxy_rest 93 | RAISING 94 | /iwbep/cx_gateway. 95 | 96 | ENDCLASS. 97 | 98 | 99 | CLASS zaf_cl_rest_petstore_client IMPLEMENTATION. 100 | 101 | 102 | METHOD if_oo_adt_classrun~main. 103 | 104 | DATA: 105 | ls_pet TYPE zaf_if_petstore_types=>tys_pet, 106 | ls_response_data TYPE zaf_if_petstore_types=>tys_pet, 107 | ls_category TYPE zaf_if_petstore_types=>tys_category, 108 | lv_http_status_code TYPE string, 109 | lv_id TYPE i, 110 | lx_gateway TYPE REF TO /iwbep/cx_gateway. 111 | 112 | 113 | TRY. 114 | mo_client_proxy = create_client_proxy( ). 115 | 116 | *Get 117 | lv_id = 2. 118 | ls_response_data = pet_read_by_id( lv_id ). 119 | 120 | out->write( |=========| ). 121 | out->write( |Read| ). 122 | out->write( |=========| ). 123 | out->write( |Name: { ls_response_data-name }| ). 124 | out->write( |Status: { ls_response_data-status }| ). 125 | CLEAR ls_response_data. 126 | 127 | *Update Status and Name 128 | ls_response_data = pet_update_name_and_status( 129 | iv_id = 7 130 | iv_name = 'new_name' 131 | iv_status = 'new_status' ). 132 | 133 | out->write( |=========| ). 134 | out->write( |Update Name and Status| ). 135 | out->write( |=========| ). 136 | out->write( |Name: { ls_response_data-name }| ). 137 | out->write( |Status: { ls_response_data-status }| ). 138 | CLEAR ls_response_data. 139 | 140 | *Create 141 | ls_category = VALUE #( 142 | id = 20 143 | name = 'Persian' ). 144 | ls_pet = VALUE #( 145 | id = 34 146 | name = 'Cat' 147 | status = 'Brand New' 148 | category = ls_category 149 | photo_urls = VALUE #( ( |url_1| ) ) ). 150 | 151 | ls_response_data = pet_create( ls_pet ). 152 | 153 | out->write( |=========| ). 154 | out->write( |Create| ). 155 | out->write( |=========| ). 156 | out->write( |Name: { ls_response_data-name }| ). 157 | out->write( |Photo URL: { ls_response_data-photo_urls[ 1 ] }| ). 158 | CLEAR ls_response_data. 159 | 160 | *Update with Put 161 | ls_pet-name = 'Schrodingers Cat'. 162 | ls_pet-status = 'Dead and Alive'. 163 | ls_pet-category = VALUE #( 164 | id = 21 165 | name = 'Mystery Kitty' ). 166 | 167 | ls_response_data = pet_update( ls_pet ). 168 | 169 | out->write( |=========| ). 170 | out->write( |Update| ). 171 | out->write( |=========| ). 172 | out->write( |Name: { ls_response_data-name }| ). 173 | out->write( |Status: { ls_response_data-status }| ). 174 | out->write( |Category-Name: { ls_response_data-category-name }| ). 175 | 176 | *Delete 177 | lv_http_status_code = pet_delete( 4 ). 178 | 179 | IF lv_http_status_code = 200. 180 | out->write( |=========| ). 181 | out->write( |Delete| ). 182 | out->write( |=========| ). 183 | out->write( 'Delete Successful!'). 184 | ENDIF. 185 | 186 | CATCH /iwbep/cx_gateway INTO lx_gateway. 187 | out->write( lx_gateway->if_message~get_text( ) ). 188 | 189 | ENDTRY. 190 | 191 | ENDMETHOD. 192 | 193 | 194 | METHOD create_client_proxy. 195 | 196 | DATA: 197 | 198 | ls_proxy_model_key TYPE /iwbep/if_cp_registry_types=>ty_s_proxy_model_key, 199 | lv_error_text TYPE string. 200 | 201 | cl_http_client=>create_by_url( 202 | EXPORTING 203 | url = 'https://petstore3.swagger.io' 204 | IMPORTING 205 | client = mo_http_client 206 | EXCEPTIONS 207 | argument_not_found = 1 208 | plugin_not_active = 2 209 | internal_error = 3 210 | pse_not_found = 4 211 | pse_not_distrib = 5 212 | pse_errors = 6 213 | OTHERS = 7 ). 214 | 215 | IF sy-subrc <> 0. 216 | MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno 217 | WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4 INTO lv_error_text. 218 | RAISE EXCEPTION TYPE lx_rest_json_pl 219 | EXPORTING 220 | iv_error_text = lv_error_text. 221 | ENDIF. 222 | 223 | "Proxy model defined in ZAF_CL_REST_PETSTORE_MODEL 224 | ls_proxy_model_key = VALUE #( repository_id = /iwbep/if_cp_registry_types=>gcs_repository_id-default 225 | proxy_model_id = 'ZAF_REST_PETSTORE' 226 | proxy_model_version = 0003 ). 227 | 228 | ro_client_proxy ?= /iwbep/cl_cp_client_proxy=>create_rest_remote_proxy( 229 | is_proxy_model_key = ls_proxy_model_key 230 | io_http_client = mo_http_client 231 | iv_do_fetch_csrf_token = abap_false 232 | iv_relative_service_root = '/api/v3'). 233 | 234 | ENDMETHOD. 235 | 236 | 237 | METHOD pet_create. 238 | *https://petstore3.swagger.io/api/v3/pet POST 239 | mo_client_proxy->create_resource( zaf_if_petstore_types=>gcs_resource_names-pets 240 | )->create_request( /iwbep/if_v4_rest_types=>gcs_http_method-post 241 | )->set_body_data( is_pet 242 | )->execute( 243 | )->get_body_data( IMPORTING ea_body_data = rs_pet ). 244 | 245 | ENDMETHOD. 246 | 247 | 248 | METHOD pet_delete. 249 | *https://petstore3.swagger.io/api/v3/pet DELETE 250 | 251 | DATA: 252 | ls_key TYPE zaf_if_petstore_types=>tys_pet. 253 | 254 | rv_http_status_code = mo_client_proxy->create_resource( zaf_if_petstore_types=>gcs_resource_names-pet_id 255 | )->set_path_template_parameters( ls_key 256 | )->create_request( /iwbep/if_v4_rest_types=>gcs_http_method-delete 257 | )->execute( )->get_http_status_code( ). 258 | 259 | ENDMETHOD. 260 | 261 | 262 | METHOD pet_read_by_id. 263 | 264 | *https://petstore3.swagger.io/api/v3/pet/{id} GET 265 | mo_client_proxy->create_resource( zaf_if_petstore_types=>gcs_resource_names-pet_id 266 | )->set_path_template_parameters( VALUE zaf_if_petstore_types=>tys_pet( id = iv_id ) 267 | )->create_request( /iwbep/if_v4_rest_types=>gcs_http_method-get 268 | )->execute( 269 | )->get_body_data( IMPORTING ea_body_data = rs_pet ). 270 | 271 | ENDMETHOD. 272 | 273 | 274 | METHOD pet_update_name_and_status. 275 | 276 | *https://petstore3.swagger.io/api/v3/pet/{id}?name={name}&status={status} POST 277 | mo_client_proxy->create_resource( zaf_if_petstore_types=>gcs_resource_names-pet_id_name_status 278 | )->set_path_template_parameters( 279 | VALUE zaf_if_petstore_types=>tys_pet( 280 | id = iv_id 281 | name = iv_name 282 | status = iv_status ) 283 | )->create_request( /iwbep/if_v4_rest_types=>gcs_http_method-post 284 | )->execute( 285 | )->get_body_data( IMPORTING ea_body_data = rs_pet ). 286 | 287 | ENDMETHOD. 288 | 289 | 290 | METHOD pet_update. 291 | 292 | *https://petstore3.swagger.io/api/v3/pet PUT 293 | mo_client_proxy->create_resource( zaf_if_petstore_types=>gcs_resource_names-pets 294 | )->create_request( /iwbep/if_v4_rest_types=>gcs_http_method-put 295 | )->set_body_data( is_pet 296 | )->execute( 297 | )->get_body_data( IMPORTING ea_body_data = rs_pet ). 298 | 299 | ENDMETHOD. 300 | 301 | METHOD constructor. 302 | 303 | mo_client_proxy = create_client_proxy( ). 304 | 305 | ENDMETHOD. 306 | 307 | ENDCLASS. 308 | -------------------------------------------------------------------------------- /src/zaf_cl_rest_petstore_client.clas.locals_imp.abap: -------------------------------------------------------------------------------- 1 | "!SAP Gateway Exception
2 | CLASS lx_rest_json_pl DEFINITION 3 | INHERITING FROM /iwbep/cx_gateway 4 | CREATE PUBLIC . 5 | 6 | PUBLIC SECTION. 7 | 8 | METHODS if_message~get_text REDEFINITION. 9 | 10 | METHODS constructor 11 | IMPORTING 12 | iv_error_text TYPE string. 13 | 14 | 15 | 16 | PROTECTED SECTION. 17 | 18 | PRIVATE SECTION. 19 | DATA mv_error_text TYPE string. 20 | 21 | 22 | ENDCLASS. 23 | 24 | 25 | 26 | CLASS lx_rest_json_pl IMPLEMENTATION. 27 | 28 | METHOD constructor. 29 | super->constructor( ). 30 | mv_error_text = iv_error_text. 31 | ENDMETHOD. 32 | 33 | 34 | METHOD if_message~get_text. 35 | result = mv_error_text. 36 | ENDMETHOD. 37 | 38 | ENDCLASS. 39 | -------------------------------------------------------------------------------- /src/zaf_cl_rest_petstore_client.clas.testclasses.abap: -------------------------------------------------------------------------------- 1 | CLASS zaf_cl_petstore_test DEFINITION DEFERRED. 2 | class zaf_cl_rest_petstore_client definition local friends 3 | zaf_cl_petstore_test. 4 | 5 | CLASS zaf_cl_petstore_test DEFINITION 6 | FINAL 7 | FOR TESTING 8 | DURATION SHORT 9 | RISK LEVEL HARMLESS. 10 | 11 | PUBLIC SECTION. 12 | 13 | METHODS: 14 | pet_operations FOR TESTING RAISING /iwbep/cx_gateway. 15 | 16 | 17 | PRIVATE SECTION. 18 | 19 | DATA mo_cut TYPE REF TO zaf_cl_rest_petstore_client. 20 | 21 | METHODS: setup RAISING /iwbep/cx_gateway. 22 | 23 | ENDCLASS. 24 | 25 | CLASS zaf_cl_petstore_test IMPLEMENTATION. 26 | 27 | 28 | METHOD pet_operations. 29 | 30 | DATA: 31 | ls_payload TYPE zaf_if_petstore_types=>tys_pet, 32 | ls_response_exp TYPE zaf_if_petstore_types=>tys_pet, 33 | ls_response_act TYPE zaf_if_petstore_types=>tys_pet, 34 | ls_category TYPE zaf_if_petstore_types=>tys_category, 35 | lv_http_status_code TYPE string, 36 | lv_id TYPE i, 37 | lx_gateway TYPE REF TO /iwbep/cx_gateway. 38 | 39 | *CREATE 40 | ls_category = VALUE #( 41 | id = 20 42 | name = 'Persian' ). 43 | ls_payload = VALUE #( 44 | id = 34 45 | name = 'Cat' 46 | status = 'Brand New' 47 | category = ls_category 48 | photo_urls = VALUE #( ( |url_1| ) ) ). 49 | 50 | ls_response_exp = ls_payload. 51 | 52 | ls_response_act = mo_cut->pet_create( ls_payload ). 53 | 54 | "Then the expected pet data should be returned. 55 | cl_abap_unit_assert=>assert_equals( exp = ls_response_exp 56 | act = ls_response_act ). 57 | CLEAR ls_response_act. 58 | 59 | *READ BY ID 60 | 61 | "When we make a get request for a pet with this id. 62 | lv_id = 34. 63 | ls_response_act = mo_cut->pet_read_by_id( lv_id ). 64 | 65 | "Then the expected pet data should be returned. 66 | cl_abap_unit_assert=>assert_equals( exp = ls_response_exp 67 | act = ls_response_act ). 68 | CLEAR ls_response_act. 69 | 70 | *UPDATE NAME AND STATUS 71 | ls_response_act = mo_cut->pet_update_name_and_status( 72 | iv_id = 34 73 | iv_name = 'new_name' 74 | iv_status = 'new_status' ). 75 | 76 | ls_response_exp-name = 'new_name'. 77 | ls_response_exp-status = 'new_status'. 78 | 79 | cl_abap_unit_assert=>assert_equals( exp = ls_response_exp 80 | act = ls_response_act ). 81 | 82 | *UPDATE 83 | ls_payload-name = 'Schrodingers Cat'. 84 | ls_payload-status = 'Dead and Alive'. 85 | ls_payload-category = VALUE #( 86 | id = 21 87 | name = 'Mystery Kitty' ). 88 | 89 | ls_response_exp = ls_payload. 90 | 91 | ls_response_act = mo_cut->pet_update( ls_payload ). 92 | 93 | cl_abap_unit_assert=>assert_equals( exp = ls_response_exp 94 | act = ls_response_act ). 95 | 96 | *DELETE 97 | lv_http_status_code = mo_cut->pet_delete( 4 ). 98 | 99 | "the expected pet data should be returned. 100 | cl_abap_unit_assert=>assert_equals( exp = 200 101 | act = lv_http_status_code ). 102 | 103 | ENDMETHOD. 104 | 105 | 106 | METHOD setup. 107 | mo_cut = NEW zaf_cl_rest_petstore_client( ). 108 | ENDMETHOD. 109 | 110 | ENDCLASS. 111 | -------------------------------------------------------------------------------- /src/zaf_cl_rest_petstore_client.clas.xml: -------------------------------------------------------------------------------- 1 | 2 |Proxy Model consuming https://petstore3.swagger.io/api/v3
2 | "! Used in client {@link ZAF_CL_REST_PETSTORE_CLIENT} 3 | CLASS zaf_cl_rest_petstore_model DEFINITION 4 | PUBLIC 5 | INHERITING FROM /iwbep/cl_v4_abs_model_prov 6 | FINAL 7 | CREATE PUBLIC . 8 | 9 | PUBLIC SECTION. 10 | 11 | METHODS /iwbep/if_v4_mp_basic_rest~define REDEFINITION. 12 | 13 | PRIVATE SECTION. 14 | 15 | "!Define the structure type and resources for Pet
16 | "! 17 | "! @parameter io_model |Proxy model
18 | "! @raising /iwbep/cx_gateway |Gateway exception
19 | METHODS define_pet 20 | IMPORTING 21 | io_model TYPE REF TO /iwbep/if_v4_rest_model 22 | RAISING 23 | /iwbep/cx_gateway . 24 | 25 | ENDCLASS. 26 | 27 | 28 | CLASS zaf_cl_rest_petstore_model IMPLEMENTATION. 29 | 30 | 31 | METHOD /iwbep/if_v4_mp_basic_rest~define. 32 | 33 | define_pet( CAST /iwbep/if_v4_rest_model( io_model ) ). 34 | 35 | ENDMETHOD. 36 | 37 | 38 | METHOD define_pet. 39 | * 40 | DATA: 41 | ls_data_container_pet TYPE zaf_if_petstore_types=>tys_pet, 42 | ls_data_container_tag TYPE zaf_if_petstore_types=>tys_tag, 43 | ls_data_container_category TYPE zaf_if_petstore_types=>tys_category, 44 | lo_structured_type TYPE REF TO /iwbep/if_v4_rest_struc_type, 45 | lo_resource TYPE REF TO /iwbep/if_v4_rest_resource, 46 | lo_operation TYPE REF TO /iwbep/if_v4_rest_operation. 47 | 48 | 49 | *Define Category 50 | lo_structured_type = io_model->create_struct_type_by_struct( 51 | iv_name = zaf_if_petstore_types=>gcs_internal_struct_type_names-category 52 | is_structure = ls_data_container_category 53 | iv_do_gen_prim_props = abap_true ). 54 | 55 | lo_structured_type->camelcase_lower_prim_prp_names( ). 56 | 57 | *Define Tag 58 | lo_structured_type = io_model->create_struct_type_by_struct( 59 | iv_name = zaf_if_petstore_types=>gcs_internal_struct_type_names-tag 60 | is_structure = ls_data_container_tag 61 | iv_do_gen_prim_props = abap_true ). 62 | 63 | lo_structured_type->camelcase_lower_prim_prp_names( ). 64 | 65 | *Define Pet 66 | lo_structured_type = io_model->create_struct_type_by_struct( 67 | iv_name = zaf_if_petstore_types=>gcs_internal_struct_type_names-pet 68 | is_structure = ls_data_container_pet 69 | iv_do_gen_prim_props = abap_true 70 | iv_do_gen_prim_prop_colls = abap_true ). 71 | 72 | lo_structured_type->camelcase_lower_prim_prp_names( ). 73 | 74 | lo_structured_type->create_structured_property( 'CATEGORY' 75 | )->set_external_name( 'category' 76 | )->set_structured_type( zaf_if_petstore_types=>gcs_internal_struct_type_names-category ). 77 | 78 | lo_structured_type->create_structured_property( 'TAGS' 79 | )->set_external_name( 'tags' 80 | )->set_structured_type( zaf_if_petstore_types=>gcs_internal_struct_type_names-tag )->set_is_collection( ). 81 | 82 | *Get by id 83 | lo_resource = io_model->create_resource( iv_name = zaf_if_petstore_types=>gcs_resource_names-pet_id 84 | iv_path_template = zaf_if_petstore_types=>gcs_resource_paths-pet_id ). 85 | 86 | lo_resource->set_path_params_struct_type( zaf_if_petstore_types=>gcs_internal_struct_type_names-pet 87 | )->create_operation( /iwbep/if_v4_rest_types=>gcs_http_method-get 88 | )->create_response_body( 89 | )->set_structured_type( zaf_if_petstore_types=>gcs_internal_struct_type_names-pet ). 90 | 91 | *Delete 92 | lo_resource->set_path_params_struct_type( zaf_if_petstore_types=>gcs_internal_struct_type_names-pet 93 | )->create_operation( /iwbep/if_v4_rest_types=>gcs_http_method-delete 94 | )->create_response_body( ). 95 | 96 | *Update Status and Name 97 | io_model->create_resource( iv_name = zaf_if_petstore_types=>gcs_resource_names-pet_id_name_status 98 | iv_path_template = zaf_if_petstore_types=>gcs_resource_paths-pet_id_name_status 99 | )->set_path_params_struct_type( zaf_if_petstore_types=>gcs_internal_struct_type_names-pet 100 | )->create_operation( /iwbep/if_v4_rest_types=>gcs_http_method-post 101 | )->create_response_body( 102 | )->set_structured_type( zaf_if_petstore_types=>gcs_internal_struct_type_names-pet ). 103 | 104 | lo_resource = io_model->create_resource( iv_name = zaf_if_petstore_types=>gcs_resource_names-pets 105 | iv_path_template = zaf_if_petstore_types=>gcs_resource_paths-pets ). 106 | 107 | *Create 108 | lo_operation = lo_resource->create_operation( /iwbep/if_v4_rest_types=>gcs_http_method-post ). 109 | lo_operation->create_request_body( 110 | )->set_structured_type( zaf_if_petstore_types=>gcs_internal_struct_type_names-pet ). 111 | lo_operation->create_response_body( 112 | )->set_structured_type( zaf_if_petstore_types=>gcs_internal_struct_type_names-pet ). 113 | 114 | *Update with put 115 | lo_operation = lo_resource->create_operation( /iwbep/if_v4_rest_types=>gcs_http_method-put ). 116 | lo_operation->create_request_body( 117 | )->set_structured_type( zaf_if_petstore_types=>gcs_internal_struct_type_names-pet ). 118 | lo_operation->create_response_body( 119 | )->set_structured_type( zaf_if_petstore_types=>gcs_internal_struct_type_names-pet ). 120 | 121 | 122 | ENDMETHOD. 123 | 124 | ENDCLASS. 125 | -------------------------------------------------------------------------------- /src/zaf_cl_rest_petstore_model.clas.xml: -------------------------------------------------------------------------------- 1 | 2 |Structure Types for Petstore API entities
2 | INTERFACE zaf_if_petstore_types 3 | PUBLIC . 4 | 5 | CONSTANTS: 6 | BEGIN OF gcs_internal_struct_type_names, 7 | pet TYPE /iwbep/if_v4_rest_types=>ty_internal_name VALUE 'PET', 8 | tag TYPE /iwbep/if_v4_rest_types=>ty_internal_name VALUE 'TAG', 9 | category TYPE /iwbep/if_v4_rest_types=>ty_internal_name VALUE 'CATEGORY', 10 | END OF gcs_internal_struct_type_names, 11 | 12 | BEGIN OF gcs_resource_names, 13 | pets TYPE /iwbep/if_v4_rest_types=>ty_internal_name VALUE `PETS`, 14 | pet_id TYPE /iwbep/if_v4_rest_types=>ty_internal_name VALUE `PET_ID`, 15 | pet_id_name_status TYPE /iwbep/if_v4_rest_types=>ty_internal_name VALUE `PET_ID_NAME_STATUS`, 16 | END OF gcs_resource_names, 17 | 18 | BEGIN OF gcs_resource_paths, 19 | pets TYPE string VALUE `/pet`, 20 | pet_id TYPE string VALUE `/pet/{id}`, 21 | pet_id_name_status TYPE string VALUE `/pet/{id}?name={name}&status={status}`, 22 | END OF gcs_resource_paths. 23 | 24 | TYPES: 25 | 26 | BEGIN OF tys_category, 27 | id TYPE i, 28 | name TYPE string, 29 | END OF tys_category, 30 | 31 | BEGIN OF tys_tag, 32 | id TYPE i, 33 | name TYPE string, 34 | END OF tys_tag, 35 | 36 | BEGIN OF tys_pet, 37 | id TYPE i, 38 | name TYPE string, 39 | category TYPE tys_category, 40 | photo_urls TYPE STANDARD TABLE OF string WITH DEFAULT KEY, 41 | tags TYPE STANDARD TABLE OF tys_tag WITH DEFAULT KEY, 42 | status TYPE string, 43 | END OF tys_pet. 44 | 45 | ENDINTERFACE. 46 | -------------------------------------------------------------------------------- /src/zaf_if_petstore_types.intf.xml: -------------------------------------------------------------------------------- 1 | 2 |