Hi I’m Philip from the HANA Academy in this series of videos we're looking at
the XS Advanced model in this video we're going to create OData
web-based access to our tables remember in the previous videos we created a
project and we created a database module a HDI container with a country and region
table in it we defined that through HDB CDS we've actually loaded some data
using the Database Explorer now we're ready to go ahead and create our OData
service now you can create an OData service with java you can also create
OData services OData version 2 with nodejs and that's what we're going to do
in this video so let's right mouse button on sales and choose new and this
time the module we want to create is a node.js module we can give it a name we
can call it whatever you want I’ll call it nodejs for example hit next and one
of the options has been there for a while is enable XSJS
support that's very important for us if you want to just create a dot XS OData
syntax you’re probably familiar if you used XS classic over the previous years
with HANA it means you can work synchronously do
synchronous JavaScript rather than having to use the default asynchronous
that you get with nodejs you can may be a bit more tricky to work with but
you're a XSJS support is quite an easy and flexible way to work so that's
it next there's actually nothing new there at that point what is new in SPS
01 is that we can see we've got some differences in the way the project has
been created now the templates created is a little hello world XSJS files in
hello world ok that's not different but if we look at the package.json which is
where all of the different node modules were referencing are you'll see that the
module names have changed so rather than SAP - XSJS and SAP - XSENV we see
we've got a different syntax we've got @ SAP and then forward slash and this
basically means that the the way that SAP provided node modules are being
distributed is through something called scopes so these are basically
scoped names scoped packages and by changing to this it means that SAP can
actually publish the SAP modules publicly and they'll they'll not be
confused with anyone else that might happen to have used SAP - at the
beginning because only SAP will publish with @ sSAP forward slash this is
the way that NPM or the node package manager works when you're working with
nodejs so @ SAP is the way to go and you'll notice that you've got in fact a
whole number of them you’ve got XSJS tests etc so though these are
the kind of ways you're going to specify your dependencies and you've got
versions now one of the challenges when you're working with nodejs is making
sure you've got the right maybe the latest version of any particular node
module that you're working with whether that's from SAP what is coming maybe
from a third party or it's a standard node one now what's been added with
SPS 01 of Web IDE for HANA is the ability to actually check those
dependencies and see if you're working with the latest versions etc etc so what
you can do for that module is right mouse button and down in the build
section you'll see that they show dependency updates now what this will do
is it will basically trigger a quick build of your project and then it will
actually identify any modules that you've got that maybe aren't actually at
the latest version that you might want to update based on the version of NPM
that’s actually been used here the version of HANA you've installed and the
packages are actually installed compared to the script and the code that
you've got here so if we look the build completed successfully but if we have a
quick look in the log file you'll see that from that build we've noticed that
there is actually SAP XSENV the environment settings for working with
XS Advanced and you see that the current build is one point two
six and that's the one we've actually asked to use but the latest available is
one point two seven so if you wanted you might want to consider going up to one
point two seven to get the latest capabilities of XSENV it's really up to
you how you want to work that instead of you having to go to the node
package manager and search on this actual module name to actually find
out what the latest version is you can actually just do that for your whole
module in one go here and it will look at all the dependencies and give you
information on them all so this actually could help you save some time and be
more flexible as you're developing with nodejs
so what we were going to do here is create an OData service so to do
that let’s go to the lib section and create a new file so a new file and
we're going to call this services.xs odata it is not particularly new
however if you right mouse button you'll see that you've got the ability to
insert an XSOData snippet maybe get you helped get you started with the syntax
and actually what I'm going to do is just get rid of that because I've
already got the code we need for our case here in the GitHub repository we've
seen it in the previous couple of videos so github.com SAP HANA Academy XSA
repository and then in sales HTML5 master detail at the end of it we've got
our services xso data syntax so let's just paste that in so we've got an
association and this is going to be very useful in the next video where we create
a master detail Fiori application based on this OData
service so I click Save now I'd want to go ahead and build and potentially run
my applications we can go ahead and run so let's go and run as a nodejs
application and that will take a few seconds to actually go through the build
process so the Builder is complete we can see that the application is now
running and we've got the URL I'm using port based routing here so you can see
that it's assigned as a port number so we can go ahead and have a go at running
the application see if it works well we get the default XSJS because that’s the
hello world but what we really want to do is to look at services.XS
OData let's have a go see what happens didn't work and there's a reason for
that we've not actually specified which HANA
system we're going to use we've just created an OData service
on its own independently so well I knew that was going to happen but what
it does is it gives us a chance to look at a couple of quite interesting aspects
the first one is that we need to go to the mta yaml file and if we
double-click it we've got the mta yaml editor so we can see that there is a
resource called HDI container and if we look at the modules we've got the
database and that nodejs now this was added for us now the database uses the
resource HDI container I'm going to copy that the nodejs module doesn't but it's
going to need to use it because that's where our data is behind the OData service
so I can just use the editor here to hit the plus sign and then paste in a
requires for that HDI container and if we just go over to the code editor you
can see what that means means that we've got in our nodejs app a requires four
named HDI container has been added we didn't have to write that code we didn't
have to worry about the tabbing or the indentation with spaces it was
all done for us so that's a great use of the MTA editor when we're working with
HANA 2 SPS01 what we also see is that the template has added a number of other
things it's created a service that would be able to access and use when we're
building maybe a Fiori app in the next video so it's actually done more
scripting than has been done in the past so the template for building a nodejs
xsjs compatibility app has been improved ok let's save our changes to
the mta yaml file what we can then do is just notice that the node modules
node_modules folder was added when we did the build and run and if you
click on it you'll see this is where we actually get to see all of the node
modules actually embedded within the project within that module and the @
SAP ones will be at the top so here you can get a list for example XSENV
it's one we’re using you can have a look at it you can actually that's where the
code is but more importantly you can get to the readme MD and if you look at that
this is where you'll get really good documentation that's always up to date
showing for every actual module such as XSENV
exactly how it works what's been changed in different releases you see I'm
scrolling through the different ways that you can use XSENV gives different
syntax examples etc etc and say and/or normally at the end you'll also have
information on what was added in different releases so this is where you
can get to the readme which can be very useful and it's actually embedded into
your project so that's in the node _modules of folder right well
we've made a change we've made our reference to the HDI container so we're
now ready to go ahead and do it again we're going to go to our module and run
it again now of course it's not going to rebuild the entire app from scratch
because I took a little bit of time what it's doing is going to basically just
make the updates in place in the existing application so when we're
developing it that means when we were rebuilding and making small changes that
the application the testing wall will happen more quickly because actually
getting the app started we'll just take a few seconds so the app’s running so
it's basically restarted let's go to our URL and try it again now this time
we find that it works we get a result we get a 406 error back that's expected
because by default OData works with XML but we only support JSON so we need to
actually say $ format equals JSON when we're working with it that's no
worries it's not going to stop it working for example we could put forward
slash $ metadata to get the metadata of the OData surface we created
and we can see that we've got an entity for example called region so if we want
we could put region be careful because that's going to pull down all of the
data in JSON format so we can see here we've got the different regions for
regions that we have in our three regions that we have in our data and
it's also we see we've got the master detail because we look at Asia we've got
the association with the countries of Asia and if we click on that association
we can now see we get information for China India and Japan so we've got an
OData service and setup with associations so we're basically ready for building a
master detail application a Fiori application which we're going to
see in the next video so what we've seen in this video is how we can set up the
nodejs application how we can work with the improvements with the MTA
editor we've seen how that packages have changed we're using the scoped naming so
@ SAP / rather than just a name that happened to begin with SAP - so these
are some of the new things with SPS 01 when we working with nodejs you can
find more HANA video tutorials on our YouTube channel if you'd like to be
informed as soon as new video tutorials are published please subscribe to the
channel you can also connect with us on LinkedIn follow us on Twitter and we
have pages on Facebook and Google+ code snippets for all of our tutorials are
published to GitHub thanks for watching