We already have our project!
We are going to start our API locally. The first step is to install the project dependencies by running the command:
npm install
Once finished, a folder will appear with all the installed libraries
We have everything ready, we only have to execute the command that will start our service, in case of modifications these are automatically updated on our local server.
cds watch
By accessing the local URL, using the "Open in New Tab" button and we will access our local API with local database
First we will add a breakpoint, for example in the extension of the service, click on the left side of the line
Then we register the project in the "Run configurations" section
Pressing play activates Debug mode with the same URL as if we use "cds watch":
When executing the query we can see how it stops at the indicated point. The request will be waiting for us to "release" the Debug
Phase 2 - Deploy to cloud
We make the minimum adaptations to our CAPm to deploy in the HANA database. To do this, we will make two small changes to files.
In the Package.json file we substitute these lines of code:
"cds": {
"requires": {
"db": {
"kind": "sql"
}
}
}
For these others:
"cds": {
"hana": {
"deploy-format": "hdbtable"
},
"requires": {
"db": {
"kind": "sql",
"credentials": {
"database": "bookshop.db"
}
}
}
}
(THIS STEP ONLY IN TRIAL ACCOUNTS) we go to the mta.yaml file and modify the final part as indicated in the comments. That is, we remove service: hana and put service: hanatrial.
type: com.sap.xs.hdi-container
parameters:
service: hana # or 'hanatrial' on trial landscapes
service-plan: hdi-shared
properties:
hdi-service-name: ${service-name}
Finally we generate the deployment files, for this, we execute the command:
cds build --for hana
We do Build and Deploy:
Deploy: Once the build is finished, a folder mta_archives will be generated and in the generated mta file, right click and "Deploy MTA Archive".
Once the deploy is finished we see our new API. We can now run a query:
npm add @sap/hana-client --save
Once installed, in the root of our project we will create a new file called "default-env.json".
In the file we will add the information that we will retrieve from the HDI service from our database, if necessary we will create a new Service Key by pressing the "Create" button and giving it a name
we copy the security information:
We add it to the file "default-env.json" embedded in the following structure where the "..." are the part copied previously and in name we must add the name of the HDI container:
{
"VCAP_SERVICES": {
"hanatrial": [],
"hana": [
{
"name": "HDI Name",
"tags": [
"hana"
],
"credentials": {
...
}
}
]
}
}
This is the result:
we are going to replace it in our package.json file:
"cds": {
"hana": {
"deploy-format": "hdbtable"
},
"requires": {
"db": {
"kind": "sql",
"credentials": {
"database": "bookshop.db"
}
}
}
}
For this:
"cds": {
"requires": {
"db": {
"kind": "hana"
}
}
}
Everything is ready, as before, we can use "cds watch" or "Run Configuration" to start the service. The result when making the request is as follows
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
50 | |
5 | |
5 | |
4 | |
4 | |
4 | |
3 | |
3 | |
3 | |
2 |