Search

Hello World!

Let’s create a simple Hello World OData service using the SAP Cloud Application Programming Model in six lines of code and in under 2 minutes.

Define a service

… using CDS:

service say {
  function hello (to:String) returns String;
}

Implement it

… for example, using Node.js express.js handlers style:

module.exports = (say)=>{
  say.on ('hello', req => `Hello ${req.data.to}!`)
}

… or Node.js es6 classes style:

module.exports = class say {
  hello(req) { return `Hello ${req.data.to}!` }
}

Note: that has limited flexibility, for example, you can register only one handler per event.

Run it

… for example, from your command line:

cds run

Consume it

… for example, from your browser:

http://localhost:4004/say/hello(to='world')