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

api response

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

$.response API

Represents the HTTP response currently being populated. This API is used for returning a result response to the xsk HTTP service caller.

Reference

  • SAP Help

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

  • Module

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

  • Sample usage:
// array of cars and their colors
let cars = [
  { make: "mercedes", color: "red" },
  { make: "audi", color: "blue" },
  { make: "toyota", color: "red" },
  { make: "vw", color: "blue" }
]

// filter by color function
function filterCarsByColor(color) {
  return cars.filter(function(car) { 
    return car.color === color;
  })
}

if ($.request.method === $.net.http.GET) {
  // get query parameter color
  let color = $.request.parameters.get("color");

  // handle some request operation 
  if (color) {
    // filter by color if passed
    let filteredCars = filterCarsByColor(color);

    // send response with filtered cars by color
    $.response.contentType = "application/json";
    $.response.status = $.net.http.OK;
    $.response.setBody(JSON.stringify({
      "cars": filteredCars
    }));
  } else {
    // send response with all cars as color param is missing
    $.response.status = $.net.http.BAD_REQUEST;
    $.response.setBody(JSON.stringify({
      "cars": cars
    }));
  }
} else {
  // unsupported method
  $.response.status = $.net.http.NOT_FOUND;
  $.response.setBody(JSON.stringify({
    "error": "not found"
  }));
}
  • Coverage
Members Description Status
body The body of the response.
cacheControl Easy access to the cache control header of the entity.
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.
status The HTTP status code of the outgoing HTTP response.
Methods Description Status
setBody() Sets the body of the entity.
followUp() Enable running a follow up job that executes in the background.
  • Issues

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

  • Unit Tests ⚠️

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