Skip to content
This repository has been archived by the owner on Aug 1, 2022. It is now read-only.

api net.http

BorisNen edited this page Jun 21, 2021 · 9 revisions

$.net.http API

Represents the http namespace with its fields.

Reference

  • SAP Help

https://help.sap.com/doc/3de842783af24336b6305a3c0223a369/2.0.03/en-US/$.net.http.html

  • Module

https://github.com/SAP/xsk/tree/main/modules/api/api-xsjs/src/main/resources/xsk/http

  • Sample usage:
let http = $.net.http;
let response_prev = require('http/v4/response');

/*
Read service.xshttpdest inside the Demo package that contains:
host=https://services.odata.org;
pathPrefix=/V4/Northwind/Northwind.svc/;
*/
let dest = http.readDestination("Demo", "service");
// Check if the file has been read properly
response_prev.println("Host: " +dest.host+ " Path Prefix: " +dest.pathPrefix);

// create client
let client = new http.Client();
let request = new http.Request(http.GET, "/"); // new Request(METHOD, PATH)
// the PATH will be prefixed by destination's pathPrefix, e.g. "/search?" on the request
// set the timeout in seconds
client.setTimeout(10);
// send the request and synchronously get the response
client.request(request, dest);
let response = client.getResponse();

// get all the cookies and headers from the response
let co = [], he = [];
for(let c in response.cookies) {
    co.push(response.cookies[c]);
}

for(let c in response.headers) {
    he.push(response.headers[c]);
}

// get the body
let body;
if(!response.body)
    body = "";
else
    body = response.body;

// close the connection
client.close();        // prevent socket leak - see xsengine.ini: [communication] - max_open_sockets_per_request

// check the contents of the response
response_prev.println("status: " +response.status+ " cookies: " +co+ " headers: " +he+ " body: " +body);
  • Coverage
Classes Description Status
Destination Contains metadata, for example, host name, port number and custom values.
Client HTTP(s) Client for outbound connectivity. This client supports HTTP and HTTPs connections over HTTP or SOCKS proxy.
Request Request class to be used with HTTP client.
Methods Description Status
readDestination(package, objectName) Returns the HTTP destination with the given name as a Destination object.
  • Issues

https://github.com/SAP/xsk/issues/20

  • Unit Tests

https://github.com/SAP/xsk/tree/main/modules/engines/engine-xsjs/src/test/resources/test/xsk/http/http.xsjs

  • Integration Tests ❌

Wiki icons legend

✅ - Feature implemented and working as supposed.
⚠️ - Feature partially implemented and needs to be finished.
❌ - Feature not implemented yet.

Project

Architecture

Tips & Tricks

Infrastructure

Troubleshooting guide

Clone this wiki locally