Skip to Content
Technical Articles
Author's profile photo Carlos Roggan

SAP Cloud Platform Backend service: Tutorial [1]: Easy API creation

 

Dear friends of APIs, welcome to this blog post which aims to help you doing your very first steps to easily create your own API in SAP Cloud Platform

Why do you need an API?

Well, first of all, because it feels good 😉
And because it is easy
And maybe, because you want to  provide a brand-new service which others can use to build an application on top of it

Still need more info?

Well, you can click on this link to read the introduction

You prefer the chilled way?

Enjoy this introduction video

You don’t like links?

Here’s my summary:
Using this offering, you can create an OData service without any coding.
You only need to provide a model file
The resulting OData service can be used to store and read data without configuring a database

Interested?

So read this blog and what you’ll be doing is:

  1. Enter your SAP Cloud Platform Cockpit
  2. Go to your Backend service
  3. Give your model
  4. Get an OData service

That’s it:  Just 4 steps to do

Ohhh, it is still looking like much effort?
4 Steps are too much???

OK, then let’s phrase it differently:

  1. Give your model to your Backend service and get your OData service immediately

That’s it. Really easy, isn’t it? Just one step to do…

 

Preparation

As usual, few preparation steps are required.

You need access to SAP Cloud Platform. If you don’t have, you can try it. Get your free Trial

Right now, the SAP Cloud Platform Backend service is a beta and has to be enabled for usage

Before really using it, you need to configure roles

This blog is part of a series of tutorials.

 

Create your first API

 

Go to your Backend service in the cloud.
You’ve probably bookmarked the link, it looks similar to this:
https://yoursubaccount-backend-service.cfapps.eu10.hana.ondemand.com/cockpit/
Otherwise, start with your cloud landing page, e.g. Trial: https://account.hanatrial.ondemand.com

Click on “APIs” in the navigation pane
Press the button “Create API”

In the “Create API” dialog, enter the following information

Name MYFIRSTAPI
Version 1
Namespace DEFAULT
Model Type CDS
Description (optional) A simple service to administrate product data
CDS Document  <see below>

 

The CDS document which is required in the dialog, has to be uploaded from your local file system
So you have to press the Browse button and navigate to a file with file extension .cds
Then press on the but….. oh…

You don’t have such file???

Oh, how surprising…

I have a file, I can hand it over to you.

 

Give your (my) model

If you don’t have a model file, you can proceed like this, to create it:

Go to your local file system, create an empty file and paste the following content into it:

 

service MyFirstService{

   entity Products {
     key ProductId : Integer; 
     Name : String;
     Category : String;
   }
}

 

Save it as MyFirstService.cds

Note:
See here for a description of tools which support the creation of CDS model files

Now you can go back to Backend service.

Again, open the dialog to Create API again, enter the required information again and now choose your model cds file

Then you can go ahead and press ….

….I don’t hear an “ohhhh”…. ? …

Good.

So finally press it, the “Create API” button in the right corner of the dialog

And  wonder what’s happening.

You get an error message like me?

Don’t worry, don’t panic, before you go to search the logs for the reason, just guess that your session has timed out.
So close the error popup and reload the browser and repeat the creation if necessary.
After successful creation, you can see your service listed in the APIS list of the cockpit.
You can quickly press the logs button and monitor the process of generation by keeping refreshing the dialog

 

You can also click on the refresh button to refresh the list of APIs and so refresh the state of the activation status of the new API

Overall, I think the creation of the API is really fast, taking in consideration that really a lot of stuff is happening under the hood

Finally, you’ve created your first API.
It is a nice little OData service

View your first API

Yes, you’ve already viewed it, but only in the list of APIs.
There’s more to view.
So click on the row to go to the details screen
Now view your API.
All of it.

But only view it, OK?
Don’t touch…
Why? See next section

Test your first API

Because now, THIS is the right chapter for touching your API…

Your API is an OData service, you’ve seen it in the first section of the API details screen.
As such, it can be accessed via URL
You can do it either in a browser.. or… do it in a browser, but using the Backend service cockpit

For convenience, the Backend service cockpit offers a piece of UI that helps you exploring your new API.
It makes things easier, you’ll figure it out while playing with it

Note:
if you get authorization error while invoking your service, you might have missed the role – blog

Scroll down to API REFERENCE

 

 

This whole section, I would consider it like a testing tool, which helps you to test your API

There is a sub-section called “Products”, which is the name of our entity which we defined in our model.
For the entity, there are several operations available, like GET, POST, etc
These operations are supported by the OData specification

Afterwards, there’s a section called “Models” and another one called “Events”. Please ignore them. Just ignore and forget them.

You remember the Models section?
– No
(correct answer)

Now click on GET
It turns out that this is a whole section which is expanded.
The section lists and explains possible URL parameters
And it also shows you how the response of your API is structured and how it would look like

Don’t try to understand why the default response is “Error”
Just ignore and forget it.
Remember: it works (I mean: it works to forget…)

The best of all: the button “Try it out”
Click it

All the parameters turn into editable state
Leave them for now
Instead, click on “Execute” right away

The GET request to the “Products” entityset is executed
Then, scroll down to the “Responses” section
There you can see the “server response” and the code 200 and the “Response body”

 

The body is empty, I mean, it contains an empty json array []

That’s because there’s no data to display. But that doesn’t matter…

Think positive:
We have a success response !

Or let’s phrase it like a hero:

We have easily created a great API and we’ve successfully tested it 

 

Next Steps

Stay tuned, more tutorials will be created…

Using the testing tool in detail
Explaining CDS
Associations 1
Associations 2
Property Facets
Custom Types
Model structure 1
Model structure 2

Keep turning to the overview page

Assigned Tags

      19 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo AMIT GUPTA
      AMIT GUPTA

      Hello Carlos

      I am not able to subscribe 'SAP Cloud Platform Backend service s. I have enabled beta features as well. When I click on subscribe button it shows processing and then it revert to its original state. Please help me.

      Author's profile photo AMIT GUPTA
      AMIT GUPTA

      Hello Carlos

      It worked when I tried in Incognito mode of the browser.

      Amit

      Author's profile photo Carlos Roggan
      Carlos Roggan
      Blog Post Author

      Hi Amit, thanks for adding the solution

      Author's profile photo Former Member
      Former Member

      Hi Carlos,

      In case of BAAS, do we procure defined HANA DB storage on CloudFoundry? or is it that the charge is per unit of data storage? So, the total charge to use BAAS would be HANA DB space utilized + number of times the odata services are invoked?

      Can you provide information on how the pricing is calculated in case of BAAS?

      Thanks

      Author's profile photo Carlos Roggan
      Carlos Roggan
      Blog Post Author

      Hello Former Member ,

      yes, you’re right, the cost of using an API depends on both: the amount of stored data and the frequency of usage.
      Since Backend service leverages the serverless scenario, the database itself is abstracted from the user, I mean you don’t need to procure HANA DB storage separately. There will be only one pricing (most probably).
      However, Backend service is currently still in BETA mode, so I cannot give concrete pricing figures.

      Author's profile photo Former Member
      Former Member

      Ok, Thank you Carlos.

      Author's profile photo Tim Platteau
      Tim Platteau

      When will BaaS get out of beta?

      Author's profile photo Carlos Roggan
      Carlos Roggan
      Blog Post Author

      Hello Tim Platteau , thank you for your question which makes absolutely sense, however, I'm afraid I'm not aware of an approximate date, it will, for the moment, continue in beta.
      Kind Regards, Carlos

      Author's profile photo Mahesh Palavalli
      Mahesh Palavalli

      Nice one Carlos Roggan . I just can't stop myself liking your blogs 🙂 😀

      Just wanted to know that is there any feature in pipeline where the entities can also be created via drag and drop kindof way? Like how salesforces does..

      As of now a lot of things are automated by this tool, if they provide the capability to add the properties assosiations and stuff via an interactive tool then it would be an awesome feature.

      Author's profile photo Carlos Roggan
      Carlos Roggan
      Blog Post Author

      @Hi Mahesh Kumar Palavalli ,

      I don’t see why you should stop yourself… ;-)))
      Hey, thank you so much for your feedback and your likes, it is highly appreciated, thanks so much!!!
      You’re mentioning a tool like a graphical editor, that’s as well my suggestion.
      On CDS side, there’s lot of enhancement going on, to support enterprise features like multi-tenancy in future, also eventing, extensibility, such stuff, which is important, but under the hood. I haven’t heard about plans for graphical tool, which we agree on ?

       

      Author's profile photo Mahesh Palavalli
      Mahesh Palavalli

      😀 😀 Carlos Roggan, Not stopping anytime soon 😛 Still covered only 13 of your blogs and planning to cover all as soon as I can 🙂 🙂

      Yeah having Graphical editor would be a nice addition 🙂 Hope to see it in future 🙂

      Author's profile photo Tim Platteau
      Tim Platteau

      Hi,

       

      When will the baas be released (not beta)?

      Author's profile photo Carlos Roggan
      Carlos Roggan
      Blog Post Author

      Hi Tim and thanks for your interest, but unfortunately I'm still not aware of any concrete info about release date, I'm so sorry
      Thanks,
      Carlos

      Author's profile photo Barathi V
      Barathi V

      Hi Carlos this document is very nice. Did you write any blog for write-back functionality. Write-back : Need to be extract data from REST API and write-back data to HANA database .

      Author's profile photo Carlos Roggan
      Carlos Roggan
      Blog Post Author

      Hello Barathi V , thanks very much for your feedback!
      Backend Service is abstraction of database, as a user you don't know about it, it is encapsulated by the OData service. So reading the REST API then writing back to the API in a subsequent request would be possible.
      Cheers, Carlos

      Author's profile photo Barathi V
      Barathi V

      Thanks much for your reply. Yes that would be possible. The API is JAVA rest API but as a abaper am just consuming this external service JSON data and i will convert to internal table format by using ABAP program.

      Then finally i wanted to update this same to DB. From the program how can we writing data back to DB using POST method?

      Thanks in advance.

       

       

       

      Author's profile photo Prasanna M
      Prasanna M

      Maybe I am late to this but I don't see this 'Backend service' or 'Create API ' buttons in my trial account. Have they been renamed or removed?

       

      thanks,

      Author's profile photo Carlos Roggan
      Carlos Roggan
      Blog Post Author

      Hello Prasanna M , sorry for inconveniences, the service has been removed for the time being, right now I don't know how and when it would be returning.
      Cheers, Carlos

      Author's profile photo Frank Lin
      Frank Lin

      I do like your blog.

      I wonder : According the roadmap. When the backend service will be formal release ?  in one year or  ???