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 srv/world.cds, content:

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

    Implement it

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

    File srv/world.js, content:

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

    … or Node.js es6 classes style.

    File srv/world.js, content:

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

    That has limited flexibility, for example, you can register only one handler per event.

    Run it

    … for example, from your command line:

    cds watch
    

    Consume it

    … for example, from your browser:

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

    Show/Hide Beta Features