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. You can also download the sample from github.com.

Define a Service

… using CDS.

File world.cds, content:

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

Implement it

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

File world.js, content:

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

… or Node.js es6 classes style.

File world.js, content:

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 serve world.cds

Consume it

… for example, from your browser:

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