Technical Articles
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:
- Enter your SAP Cloud Platform Cockpit
- Go to your Backend service
- Give your model
- 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:
- 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
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.
Hello Carlos
It worked when I tried in Incognito mode of the browser.
Amit
Hi Amit, thanks for adding the solution
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
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.
Ok, Thank you Carlos.
When will BaaS get out of beta?
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
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.
@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
Â
đ đ 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 đ
Hi,
When will the baas be released (not beta)?
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
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 .
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
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.
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,
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
I do like your blog.
I wonder : According the roadmap. When the backend service will be formal release ? in one year or ???