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

api request

Ayhan Rashidov edited this page Sep 27, 2021 · 11 revisions

$.request API

Represents the client HTTP request currently being processed. This API is used for retrieving request data from the xsk HTTP service caller.

Reference

  • SAP Help

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

  • Module

https://github.com/SAP/xsk/blob/main/modules/api/api-xsjs/src/main/resources/META-INF/dirigible/xsk/web/web.js

  • Sample usage:
function getUser(id) {
    // retrieve user by id
}

function createUser(data) {
    // create user
}

function deleteUser(id) {
    // delete user
}

if(/\/?users$/.test($.request.queryPath)) {
    const id = $.request.parameters.get("id");
    if ($.request.method === $.net.http.PUT) {
        if($.request.contentType === "application/json") {
            createUser($.request.body);

            $.response.setBody(`created user [${ JSON.stringify($.request.body.asString()) }]`);
        } else {
            $.response.setBody(JSON.stringify({
                "error": "Unsupported content type."
            }));
        }
    } else if(id) {
        switch($.request.method) {
            case $.net.http.GET:
                getUser(id);

                $.response.setBody(`retrieved user with id ${ id }`);

                break;
            case $.net.http.DELETE:
                deleteUser(id);

                $.response.setBody(`deleted user with id [${ id }]`);

                break;
            default:
                $.response.setBody(JSON.stringify({
                    "error": `Unsupported method [${ $.request.method }]` 
                }));
        }
    } else {
        $.response.setBody(JSON.stringify({
            "error": "Missing required parameter [id]"
        }));
    }
} else {
    $.response.setBody(JSON.stringify({ 
        "error": `Unsupported query path [${ $.request.queryPath }]` 
    }));
}
  • Coverage
Members Description Status
body The body of the request.
contentType The content type of the entity.
cookies The cookies associated with the entity.
entities The sub-entities of the entity.
headers The headers of the entity.
language Language of the request in IETF (BCP 47) format.
method The HTTP method of the incoming HTTP request.
parameters The parameters of the entity.
path The URL path specified in the request.
queryPath The URL query path specified in the request.
Methods Description Status
setBody() Sets the body of the entity.
  • Issues

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

  • Unit Tests ⚠️

https://github.com/SAP/xsk/tree/main/modules/engines/engine-xsjs/src/test/resources/test/xsk/request/request.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