npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@sapmentors/cds-scp-api

v1.0.4

Published

CDS Extension for External Service Consumption

Downloads

121

Readme

CDS-SCP-API Node Module

CDS Extension for SAP Cloud Platform API Consumption

The node module CDS-SCP-API simplifies the consuming external API from SAP OnPremise & Cloud APIs, Microsoft Office 365 APIs, Google Cloud Platform APIs, and other REST APIs in a Cloud Application Programming (CAP) Model on the SAP Cloud Platform. The module provides:

  • Fluent API consumption concept
  • Endpoint and Configuration using SAP Cloud Platform Destination and Connectivity services
  • Support of all kind of APIs including SAP OnPremise & Cloud OData and Rest APIs, Microsoft Office 365 APIs, Google Cloud Platform APIs and other REST APIs
  • Easy API http request configuration based on Axios config options

History

Jhodel Cailan initially started the CDS Extension concept. SAP Mentor Robert Eijpe created a similar concept integrating Microsoft Azure and Google Cloud APIs into a CDS external services concept. The SAP Devtoberfest 2020 challenge brought concepts together. And this results in a CDS-SCP-API Node Module for the community, making SAP developers' lives better.

Installation

Using npm:

> npm install @sapmentors/cds-scp-api

Javascript/Node.js Code

// Load the module
const cdsapi = require("cds-scp-api");

// Create a connection
const service = await cdsapi.connect.to("SCPDestination");

// Request the API using Axios Config
let result = await service.run({
               url: "/pathOfService"
             })

Example Programs

Click here for examples and environment setup

Supported Destination Types

  • Internet Destinations with No Authentication
  • Internet Destinations with Basic Authentication
  • Internet Destinations with Client Credentials Authentication (including Microsoft Azure)
  • Internet Destinations with JWT token Authentication (currently only Google Cloud Platform)
  • OnPremise Destination and Connectivity via Cloud Connector with No Authentication
  • OnPremise Destinations and Connectivity via Cloud Connector with Basic Authentication

SCP Destination Configuration Examples

CDS-SCP-API Config Settings

The CDS-SCP-API is an SAP Cloud Platform layer on top of Axios. The configuration settings of the CDS-SCP-API service.run code is simular to Axios options, which are documented here. CDS-SCP-API will ignore the Axios config settings for the authentification, the proxy settings, and the baseURL. The CDS-SCP-API retrieves these settings from the SAP Cloud Platform Destination & Connectivity services.

Compare Axios with CDS-SCP-API

  • Axios implementation

    async function AxiosGetRequestwithBasicAuthentication() {
        return await axios({
        	url: 'https://sapes5.sapdevcenter.com/sap/opu/odata/sap/EPM_REF_APPS_SHOP_SRV/Products?$top=2',
      	  auth: {
      		  username: '<SAP S-number>',
      		  password: '<My password>'
      	  }
        })
    }
  • CDS-SCP-API implementation

    async function InternetAPIGetRequestwithBasicAuthentication() {
        const service = await cdsapi.connect.to("ES5");
        return await service.run({
      	  url: "/sap/opu/odata/sap/EPM_REF_APPS_SHOP_SRV/Products?$top=2"
        })
    }  

CDS-SCP-API implementation uses relative URLs, and authorization is configured in the SAP Cloud Platform and handled by the CDS-SCP-API implementation.

Post requests with CSRF token protection

async function InternetAPIPostRequestwithBasicAuthentication() {
  const product = {
  	"ProductID": "NL4B-101",
  	"TypeCode": "PR",
  	"Category": "Notebooks",
  	"Name": "Psychiatric Help",
  	"NameLanguage": "EN",
  	"Description": "",
  	"DescriptionLanguage": "",
  	"SupplierID": "0100000000",
  	"SupplierName": "SAP",
  	"TaxTarifCode": 1,
  	"MeasureUnit": "EA",
  	"WeightMeasure": "0.000",
  	"WeightUnit": "",
  	"CurrencyCode": "EUR",
  	"Price": "0.05",
  	"Width": "0.000",
  	"Depth": "0.000",
  	"Height": "0.000",
  	"DimUnit": "",
  	"CreatedAt": "\/Date(1602106635169)\/",
  	"ChangedAt": "\/Date(1602106635169)\/"
  }

  const service = await cdsapi.connect.to("ES5");
  return await service.run({
  	url: "/sap/opu/odata/IWBEP/GWSAMPLE_BASIC/ProductSet",
  	method: "post",
  	headers: {
  		'content-type': 'application/json'
  	},
  	data: product,
  	csrfProtection: true
  })
}

When request needs a X-CSRF token to fulfill, you can easily add the setting csrfProtection: true

Simultaneous requests

async function SimultaneousRequests() {
  const service = await cdsapi.connect.to("ES5")
  axios.all([
  	service.run({
  		url: "/sap/opu/odata/sap/EPM_REF_APPS_SHOP_SRV/Products?$top=2"
  	}),
  	service.run({
  		url: "/sap/opu/odata/sap/EPM_REF_APPS_SHOP_SRV/Products?$top=3"
  	})
  ])
  	.then(axios.spread((request1, request2) => {
  		console.log('Results request1: ', request1.d.results[0].Name);
  		console.log('Results request2: ', request2.d.results[0].Name);
  	}));

}