{"id":16163406,"url":"https://github.com/gregorwolf/cap-service-mashup","last_synced_at":"2026-03-18T18:10:53.099Z","repository":{"id":169150518,"uuid":"644608094","full_name":"gregorwolf/cap-service-mashup","owner":"gregorwolf","description":"CAP Service Mashup","archived":false,"fork":false,"pushed_at":"2025-03-30T07:57:49.000Z","size":528,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-04-07T04:30:58.270Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"HTML","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gregorwolf.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-05-23T22:06:27.000Z","updated_at":"2025-03-30T07:57:52.000Z","dependencies_parsed_at":"2024-11-02T08:40:48.764Z","dependency_job_id":"353730e4-1171-4070-814a-d2b2ed27a514","html_url":"https://github.com/gregorwolf/cap-service-mashup","commit_stats":null,"previous_names":["gregorwolf/cap-service-mashup"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/gregorwolf/cap-service-mashup","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gregorwolf%2Fcap-service-mashup","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gregorwolf%2Fcap-service-mashup/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gregorwolf%2Fcap-service-mashup/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gregorwolf%2Fcap-service-mashup/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gregorwolf","download_url":"https://codeload.github.com/gregorwolf/cap-service-mashup/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gregorwolf%2Fcap-service-mashup/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28596087,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-20T02:08:49.799Z","status":"ssl_error","status_checked_at":"2026-01-20T02:08:44.148Z","response_time":117,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-10T02:35:30.427Z","updated_at":"2026-01-20T05:02:10.455Z","avatar_url":"https://github.com/gregorwolf.png","language":"HTML","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Create a Service Mashup using the SAP Cloud Application Programming Model\n\nIt contains these folders and files, following our recommended project layout:\n\n| File or Folder | Purpose                              |\n| -------------- | ------------------------------------ |\n| `app/`         | content for frontend UI goes here    |\n| `db/`          | your domain models and data go here  |\n| `srv/`         | your service models and code go here |\n| `package.json` | project metadata and configuration   |\n| `README.md`    | this getting started guide           |\n\n## Pre-requisites\n\n- SAP BTP Trial or Free Tier Account\n- activated Cloud Foundry Environment\n- activated and started SAP HANA Cloud instance\n- SAP Business Application Studio with CAP Dev Space already setup\n\n## Next Steps\n\n- Open a new terminal and run `cds watch`\n- (in VS Code simply choose _**Terminal** \u003e Run Task \u003e cds watch_)\n- Test the endpoint using the REST Client script in `test/mashup.http`\n\n## Build, Deploy in SAP BTP Cloud Foundry\n\nBuild:\n\n```\nmbt build\n```\n\nLogin:\n\n```\ncf login -a \u003cYour BTP Cloud Foundry API Endpoint\u003e -o \u003cCF-Organization\u003e -s \u003cCF-Space\u003e --sso\n```\n\nDeploy:\n\n```\ncf deploy mta_archives/cap-service-mashup_1.0.0.mtar\n```\n\nFind the Link to the App `cap-service-mashup` in the SAP BTP Cockpit and open it in a new browser tab. You should see a link to the `Hello` function.\n\n## Create a branch for the next steps\n\nTo make it easy to switch also to the `dev` branch with contains the solution you should create a new branch `MasteringSAP` by running:\n\n```bash\ngit checkout -b MasteringSAP\n```\n\nyou can then either commit or stash your changes and switch to the `dev` branch by running:\n\n```bash\ngit checkout dev\n```\n\n## Discover the S/4HANA (Cloud) Business Partner API\n\nFind the API by searching https://api.sap.com/ for \"Business Partner\" and filter for S/4HANA Cloud:\n\n![api.sap.com S/4HANA Cloud Business Partner (A2X) API](./assets/api.sap.com-BP-A2X.png)\n\nLogin and use the tryout function to test the GET request of the Business Partner Endpoint (/A_BusinessPartner).\n\n## Import the service\n\nSwitch back to Overview to download the API specification in EDMX format. Store it in `srv/external`. If you have trouble downloading the file use the one from the `assets` folder.\n\nTranslate the EDMX file to CAP CDS using:\n\n```\ncds import srv/external/API_BUSINESS_PARTNER.edmx --keep-namespace --as cds\n```\n\nThis will create the file `srv/external/API_BUSINESS_PARTNER.cds` and add:\n\n```JSON\n      \"API_BUSINESS_PARTNER\": {\n        \"kind\": \"odata-v2\",\n        \"model\": \"srv/external/API_BUSINESS_PARTNER\"\n      }\n```\n\nto the cds.requires section in `package.json`.\n\n## Create a local mock\n\nStart the CAP Application with\n\n```bash\ncds watch\n```\n\nTest the endpoint with the script `test/api-business-partner.http`.\n\nProvide mock data for the entity `A_BusinessPartner` by copying `assets/API_BUSINESS_PARTNER-A_BusinessPartner.json` to `srv/data`. The CAP Service should restart and when you query now the entity `A_BusinessPartner` you should get 3 results.\n\nNow you can start the mock only by running:\n\n```bash\ncds mock API_BUSINESS_PARTNER\n```\n\nNotice the output:\n\n```\n[cds] - connect using bindings from: { registry: '~/.cds-services.json' }\n```\n\nOpen the `~/.cds-services.json` file. This file provides a local service lookup.\n\n## Implement service consumption in CAP\n\nUpdate `srv/mashup-service.cds` with the following content:\n\n```CDS\nusing {API_BUSINESS_PARTNER as bp} from './external/API_BUSINESS_PARTNER';\n\nservice MashupService {\n    entity BusinessPartners as projection on bp.A_BusinessPartner;\n    function Hello(name : String) returns String;\n}\n```\n\nStart a new terminal and run:\n\n```bash\ncds watch\n```\n\nCall the endpoint with the REST Client script \"test service consumption\" in `test/mashup.http`. You will get this result body:\n\n```JSON\n{\n  \"error\": {\n    \"code\": \"501\",\n    \"message\": \"Entity \\\"MashupService.BusinessPartner\\\" is annotated with \\\"@cds.persistence.skip\\\" and cannot be served generically.\"\n  }\n}\n```\n\nThat is due to the missing service implementation. Let's create it by replacing the content of `srv/mashup-service.js` with:\n\n```JavaScript\nconst cds = require(\"@sap/cds\");\nconst LOG = cds.log(\"dataload\");\n\nmodule.exports = cds.service.impl(async (srv) =\u003e {\n  const bpService = await cds.connect.to(\"API_BUSINESS_PARTNER\");\n\n  srv.on(\"READ\", \"BusinessPartners\", (req) =\u003e {\n    LOG.info(\"READ BusinessPartners\");\n    return bpService.run(req.query);\n  });\n\n  srv.on(\"Hello\", (req) =\u003e `Hello ${req.data.name}!`);\n});\n```\n\nRun the REST Client script again. You will get another error:\n\n```JSON\n{\n  \"error\": {\n    \"code\": \"502\",\n    \"message\": \"Error during request to remote service:\n    Cannot find module '@sap-cloud-sdk/http-client' ...\"\n  }\n}\n```\n\nFix this by adding the following npm modules:\n\n```bash\nnpm add @sap-cloud-sdk/http-client@3.x @sap-cloud-sdk/util@3.x @sap-cloud-sdk/connectivity@3.x\n```\n\nStart\n\n```bash\ncds watch\n```\n\nagain and try the REST Client request.\n\n## Call remote service during development\n\nCreate a file `default-env.json` and add the following content and fill in your API Key:\n\n```JSON\n{\n  \"destinations\": [\n    {\n      \"name\": \"S4H\",\n      \"url\": \"https://sandbox.api.sap.com/s4hanacloud\",\n      \"headers\": {\n        \"APIKey\": \"Your own api.sap.com API Key\"\n      }\n    }\n  ]\n}\n```\n\nadjust the service configuration in the `package.json`\n\n```JSON\n      \"API_BUSINESS_PARTNER\": {\n        \"kind\": \"odata-v2\",\n        \"model\": \"srv/external/API_BUSINESS_PARTNER\",\n        \"[sandbox]\": {\n          \"credentials\": {\n            \"destination\": \"S4H\",\n            \"requestTimeout\": 30000,\n            \"path\": \"/sap/opu/odata/sap/API_BUSINESS_PARTNER\"\n          }\n        }\n      }\n```\n\nstart the backend using:\n\n```bash\ncds run --profile sandbox\n```\n\nRun now the REST Client request \"test service consumption against the api.sap.com sandbox\"\n\n## Create a destination to the api.sap.com sandbox\n\nImport the file `API_Sandbox` into your BTP Subaccount and add the Additional Property:\n\n```\nURL.headers.apikey\n```\n\nfilled with your own api.sap.com API Key.\n\n## Test the service via the destination service\n\nWith [Hybrid Testing](https://cap.cloud.sap/docs/advanced/hybrid-testing#hybrid-testing) it's possible to [Connect to Remote Services from Local](https://cap.cloud.sap/docs/guides/using-services#connect-to-remote-services-from-local). When you followed the workshop from the beginning and deployed the CAP app to BTP Cloud Foundry you can execute the following commands:\n\n```bash\ncf create-service-key cap-service-mashup-auth cap-service-mashup-auth-key\ncf csk cap-service-mashup-destination cap-service-mashup-destination-key\ncds bind -2 cap-service-mashup-auth,cap-service-mashup-destination\n```\n\nThis created a `.cdsrc-private.json` file that contains the bound services. To use this service binding this section needs to be added to `package.json`:\n\n```JSON\n,\n        \"[hybrid]\": {\n          \"credentials\": {\n            \"destination\": \"API_Sandbox\",\n            \"requestTimeout\": 30000,\n            \"path\": \"/s4hanacloud/sap/opu/odata/sap/API_BUSINESS_PARTNER\"\n          }\n        }\n```\n\nNow you can run:\n\n```bash\ncds watch --profile hybrid\n```\n\n## Consume the service via the deployed app\n\nBefore you can deploy and run the app this section needs to be added to `package.json`:\n\n```JSON\n,\n        \"[production]\": {\n          \"credentials\": {\n            \"destination\": \"API_Sandbox\",\n            \"requestTimeout\": 30000,\n            \"path\": \"/s4hanacloud/sap/opu/odata/sap/API_BUSINESS_PARTNER\"\n          }\n        }\n```\n\nThen run the build \u0026 deploy from the beginning. Then try\n\n```\nhttps://\u003corg\u003e-\u003cspace\u003e-cap-service-mashup.cfapps.\u003cregion\u003e.hana.ondemand.com/mashup/BusinessPartners?$top=10\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgregorwolf%2Fcap-service-mashup","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgregorwolf%2Fcap-service-mashup","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgregorwolf%2Fcap-service-mashup/lists"}