SlideShare une entreprise Scribd logo
1  sur  28
Appcelerator Node.ACS
Adding server-side functionality to share data between apps
within the Appcelerator ecosystem
TiLondon
Martin Hudson
March 2014
WHAT is node.js?
“Node.js is a platform built on Chrome's JavaScript runtime for easily
building fast, scalable network applications. Node.js uses an event-driven,
non-blocking I/O model that makes it lightweight and efficient, perfect for
data-intensive real-time applications that run across distributed devices.”
nodejs.org
•Appcelerator have provided an out-of-the-box service embedded directly
into Titanium Studio.
•Fully integrates with Appcelerator Cloud Services (ACS)
WHy would you use it?
APIs
Web service
endpoints
Service 1
Service 2
Service 3
We want to
talk to
external
services to
retrieve
information
Why would you use it?
- orchestration
APIs
Web service
endpoints
Reduce messages - each can take 0.5s to create and tear
down over 3G network - then send the payload!
WHy would you use it?
- Abstraction
APIs
Web service
endpoints
Swap out 3rd party suppliers without redeploying the app
Credit
card
process
WHy would you use it?
- integration & minification
APIs
Web service
endpoints
Simplify complex API responses into small JSON packets
creating a node.js webservice
To create a new widget, right click the project name in the Titanium Studio
project view... and select New Node.ACS Service.→
Doing it this way puts ACS in the same project tree; particularly useful when
using version control as your app code is synched with the webservice.
Project file structure
Doing it this way puts ACS in the same project tree; particularly useful when
using version control as your app code is synched with the webservice.
An ACS folder is created; we are interested in the controllers and config.js
TESTING The service
Right click the project name in the Titanium Studio project view... and select
Publish Publish Node.ACS Service.→
TESTING The service
If you are sending sensitive data, change from http:// to https://. We often
just publish directly to the cloud and put debugging and error info into the
response stream. That way we can switch debugging on in production if
something mis-behaves.
In TiApp.xml you can change the location of the service from localhost to the
public url of the published service. This enables you to easily test on real
devices. Stay on localhost for debugging.
Project file structure
The “controllers” folder
holds a file “application.js” by
default; we use this to hold
our web services.
We can create as many
controllers as we like, each
containing logical groups of
web services.
“config.js” is used to map our web service methods to real-world urls.
We also specify if the service call uses PUSH or GET.
TESTING The service
Use the public url you stored in TiApp.xml and post it into a browser; you
should see the services running.
the “config.js” file shows the routing for the default call to the service and
points to { "path": "/", "callback": "application#index" }
in the controller, “application.js” contains the method “index”
function index(req, res) {
res.render('index', { title: 'Welcome to Node.ACS!' });
}
Building services
To create a new service, right click the project name in the Titanium Studio
project view... and select New Node.ACS Method.→
Building services
To create a new service, right click the project name in the Titanium Studio
project view... and select New Node.ACS Method.→
Specify the web method name
you want to expose, I’m going to
create a method called “testGet”
Building services
You will see a new file “services.js” has been created and the “testGet”
method added.
“config.js” will also have changed,
it now contains the routing to
new “testGet” method. By
default, the method is always set
to GET.
Building services
Manually create another method “testPost” and manually modify “config.js”
as well.
don’t forget to change the
“testPost” method from “get” to
“post” in “config.js”
passing data
GET requests pass in data via.
the query string
POST requests pass in data via.
the request body
the “req” object contains the http request, we construct the response and
put it into the “send” function of the “res” object. NOTE: we can simply
construct the JSON response and return it.
asynchronous methods
node.js is a great, lightweight server; but you need to understand how to
make the best use of it.
When we make a call and it is serviced by the server, the server blocks all
other incoming requests until it processes the current call.
If the service is to be scalable we need to ensure that requests process
quickly. For anything but the most trivial calls like the test examples we
created we need to process methods asynchronously.
configuring the client
Publish the new node.js node changes into production.
configuring the client
This auto-generates the bindings that the app needs to connect to the
node.js server. It puts the bindings file into the “Resources” folder. If you
are developing in Alloy you will need to move it because it will be
overwritten by the Alloy compiler when you next do a clean build...
In the Titanium Studio project view select Node.ACS Import Node.ACS→
Bindings.
and select the service we have built.
Check the alloy.js file from the list and
click OK
configuring the client
If you add new web services you can either repeat and rinse this process, or
simply add the extra method references into bindings file.
We create a “lib” folder off the root of the “app” folder and put the bindings
file into it.
configuring the client
In alloy.js you will see we have created the reference to our service.
Edit this to create a global we can now reference from wherever we need
to.
configuring the client
If you look in the bindings file that was auto generated you will see our new
web service methods.
editing the bindings
Unfortunately, the auto-generated file won’t handle get requests that have
parameters in the query string. Add the following local function to the
bindings file...
editing the bindings
and modify the get method to push the serialized data into the query string.
Oh and remember to remove the “data” object from within “InvokeService”
too...
Testing the code
Create a test harness in index.xml and index.js as follows:
index.xml index.js
Testing the code
Thank you
Source code: http://bit.ly/1jZHJvb
Slideshare: http://slidesha.re/1myDc7s
check out our other slideshares:
Slideshare: http://bit.ly/alloy-customTableViewSlides
Mobile Data Systems Ltd.Turnkey mobile consultancy
www.mobiledatasystems.co
martin.hudson@mobiledatasystems.co

Contenu connexe

Tendances

Who Are You and What Do You Want? Working with OAuth in SharePoint 2013.
Who Are You and What Do You Want? Working with OAuth in SharePoint 2013.Who Are You and What Do You Want? Working with OAuth in SharePoint 2013.
Who Are You and What Do You Want? Working with OAuth in SharePoint 2013.Eric Shupps
 
Server Controls of ASP.Net
Server Controls of ASP.NetServer Controls of ASP.Net
Server Controls of ASP.NetHitesh Santani
 
Labs And Walkthroughs
Labs And WalkthroughsLabs And Walkthroughs
Labs And WalkthroughsBryan Tuttle
 
Evolution of the REST API
Evolution of the REST APIEvolution of the REST API
Evolution of the REST APIJeremyOtt5
 
ASP.NET 03 - Working With Web Server Controls
ASP.NET 03 - Working With Web Server ControlsASP.NET 03 - Working With Web Server Controls
ASP.NET 03 - Working With Web Server ControlsRandy Connolly
 
Cejv659 week09 glassfish-s14
Cejv659 week09 glassfish-s14Cejv659 week09 glassfish-s14
Cejv659 week09 glassfish-s14Ken Fogel
 
Creating REST Webservice With NetBeans
Creating REST Webservice With NetBeansCreating REST Webservice With NetBeans
Creating REST Webservice With NetBeansNeil Ghosh
 
AWS IoT 핸즈온 워크샵 - 실습 5. DynamoDB에 센서 데이터 저장하기 (김무현 솔루션즈 아키텍트)
AWS IoT 핸즈온 워크샵 - 실습 5. DynamoDB에 센서 데이터 저장하기 (김무현 솔루션즈 아키텍트)AWS IoT 핸즈온 워크샵 - 실습 5. DynamoDB에 센서 데이터 저장하기 (김무현 솔루션즈 아키텍트)
AWS IoT 핸즈온 워크샵 - 실습 5. DynamoDB에 센서 데이터 저장하기 (김무현 솔루션즈 아키텍트)Amazon Web Services Korea
 
Windows Server AppFabric
Windows Server AppFabricWindows Server AppFabric
Windows Server AppFabricRobert MacLean
 
PromQL Deep Dive - The Prometheus Query Language
PromQL Deep Dive - The Prometheus Query Language PromQL Deep Dive - The Prometheus Query Language
PromQL Deep Dive - The Prometheus Query Language Weaveworks
 
ASP.NET User Controls - 20090828
ASP.NET User Controls - 20090828ASP.NET User Controls - 20090828
ASP.NET User Controls - 20090828Viral Patel
 
Azure Durable Functions (2018-06-13)
Azure Durable Functions (2018-06-13)Azure Durable Functions (2018-06-13)
Azure Durable Functions (2018-06-13)Paco de la Cruz
 
AWS November Webinar Series - From Local Development to Production Using the ...
AWS November Webinar Series - From Local Development to Production Using the ...AWS November Webinar Series - From Local Development to Production Using the ...
AWS November Webinar Series - From Local Development to Production Using the ...Amazon Web Services
 
Msdn Workflow Services And Windows Server App Fabric
Msdn Workflow Services And Windows Server App FabricMsdn Workflow Services And Windows Server App Fabric
Msdn Workflow Services And Windows Server App FabricJuan Pablo
 
Introduction to Azure logic apps
Introduction to Azure logic appsIntroduction to Azure logic apps
Introduction to Azure logic appsGeorge Grammatikos
 

Tendances (20)

Who Are You and What Do You Want? Working with OAuth in SharePoint 2013.
Who Are You and What Do You Want? Working with OAuth in SharePoint 2013.Who Are You and What Do You Want? Working with OAuth in SharePoint 2013.
Who Are You and What Do You Want? Working with OAuth in SharePoint 2013.
 
Server Controls of ASP.Net
Server Controls of ASP.NetServer Controls of ASP.Net
Server Controls of ASP.Net
 
Ajax and ASP.NET AJAX
Ajax and ASP.NET AJAXAjax and ASP.NET AJAX
Ajax and ASP.NET AJAX
 
Firebase overview
Firebase overviewFirebase overview
Firebase overview
 
Hasgeek meteor workshop
Hasgeek meteor workshop Hasgeek meteor workshop
Hasgeek meteor workshop
 
Web controls
Web controlsWeb controls
Web controls
 
Controls
ControlsControls
Controls
 
Labs And Walkthroughs
Labs And WalkthroughsLabs And Walkthroughs
Labs And Walkthroughs
 
Evolution of the REST API
Evolution of the REST APIEvolution of the REST API
Evolution of the REST API
 
ASP.NET 03 - Working With Web Server Controls
ASP.NET 03 - Working With Web Server ControlsASP.NET 03 - Working With Web Server Controls
ASP.NET 03 - Working With Web Server Controls
 
Cejv659 week09 glassfish-s14
Cejv659 week09 glassfish-s14Cejv659 week09 glassfish-s14
Cejv659 week09 glassfish-s14
 
Creating REST Webservice With NetBeans
Creating REST Webservice With NetBeansCreating REST Webservice With NetBeans
Creating REST Webservice With NetBeans
 
AWS IoT 핸즈온 워크샵 - 실습 5. DynamoDB에 센서 데이터 저장하기 (김무현 솔루션즈 아키텍트)
AWS IoT 핸즈온 워크샵 - 실습 5. DynamoDB에 센서 데이터 저장하기 (김무현 솔루션즈 아키텍트)AWS IoT 핸즈온 워크샵 - 실습 5. DynamoDB에 센서 데이터 저장하기 (김무현 솔루션즈 아키텍트)
AWS IoT 핸즈온 워크샵 - 실습 5. DynamoDB에 센서 데이터 저장하기 (김무현 솔루션즈 아키텍트)
 
Windows Server AppFabric
Windows Server AppFabricWindows Server AppFabric
Windows Server AppFabric
 
PromQL Deep Dive - The Prometheus Query Language
PromQL Deep Dive - The Prometheus Query Language PromQL Deep Dive - The Prometheus Query Language
PromQL Deep Dive - The Prometheus Query Language
 
ASP.NET User Controls - 20090828
ASP.NET User Controls - 20090828ASP.NET User Controls - 20090828
ASP.NET User Controls - 20090828
 
Azure Durable Functions (2018-06-13)
Azure Durable Functions (2018-06-13)Azure Durable Functions (2018-06-13)
Azure Durable Functions (2018-06-13)
 
AWS November Webinar Series - From Local Development to Production Using the ...
AWS November Webinar Series - From Local Development to Production Using the ...AWS November Webinar Series - From Local Development to Production Using the ...
AWS November Webinar Series - From Local Development to Production Using the ...
 
Msdn Workflow Services And Windows Server App Fabric
Msdn Workflow Services And Windows Server App FabricMsdn Workflow Services And Windows Server App Fabric
Msdn Workflow Services And Windows Server App Fabric
 
Introduction to Azure logic apps
Introduction to Azure logic appsIntroduction to Azure logic apps
Introduction to Azure logic apps
 

Similaire à Add server-side functionality to share data between apps using Appcelerator Node.ACS

3 Ways to Get Started with a React App in 2024.pdf
3 Ways to Get Started with a React App in 2024.pdf3 Ways to Get Started with a React App in 2024.pdf
3 Ways to Get Started with a React App in 2024.pdfBOSC Tech Labs
 
Final Report To Executive ManagersXXXXXCCA 625Un
Final Report To Executive ManagersXXXXXCCA 625UnFinal Report To Executive ManagersXXXXXCCA 625Un
Final Report To Executive ManagersXXXXXCCA 625UnChereCheek752
 
Build Message-Based Web Services for SOA
Build Message-Based Web Services for SOABuild Message-Based Web Services for SOA
Build Message-Based Web Services for SOAJeffrey Hasan
 
Tips and Tricks For Faster Asp.NET and MVC Applications
Tips and Tricks For Faster Asp.NET and MVC ApplicationsTips and Tricks For Faster Asp.NET and MVC Applications
Tips and Tricks For Faster Asp.NET and MVC ApplicationsSarvesh Kushwaha
 
Application integration framework & Adaptor ppt
Application integration framework & Adaptor pptApplication integration framework & Adaptor ppt
Application integration framework & Adaptor pptAditya Negi
 
Why use .net by naveen kumar veligeti
Why use .net by naveen kumar veligetiWhy use .net by naveen kumar veligeti
Why use .net by naveen kumar veligetiNaveen Kumar Veligeti
 
ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010
ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010
ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010vchircu
 
Serverless solution architecture in AWS
Serverless solution architecture in AWSServerless solution architecture in AWS
Serverless solution architecture in AWSRuncy Oommen
 
Background Tasks with Worker Service
Background Tasks with Worker ServiceBackground Tasks with Worker Service
Background Tasks with Worker Servicessusere19c741
 
Cloud Readiness : CAST & Microsoft Azure Partnership Overview
Cloud Readiness : CAST & Microsoft Azure Partnership OverviewCloud Readiness : CAST & Microsoft Azure Partnership Overview
Cloud Readiness : CAST & Microsoft Azure Partnership OverviewCAST
 
Webservices in SalesForce (part 1)
Webservices in SalesForce (part 1)Webservices in SalesForce (part 1)
Webservices in SalesForce (part 1)Mindfire Solutions
 
WebServices using Soap
WebServices using SoapWebServices using Soap
WebServices using SoapMohammed625
 
SoapUi using WebServices
SoapUi using WebServicesSoapUi using WebServices
SoapUi using WebServicesAbdulImrankhan7
 
WebServices using Soapui
WebServices using SoapuiWebServices using Soapui
WebServices using Soapuijaveed_mhd
 
Day 4 - Cloud Migration - But How?
Day 4 - Cloud Migration - But How?Day 4 - Cloud Migration - But How?
Day 4 - Cloud Migration - But How?Amazon Web Services
 
Custom connector development using mule DevKit
Custom connector development using mule DevKitCustom connector development using mule DevKit
Custom connector development using mule DevKitRamakrishna Narkedamilli
 

Similaire à Add server-side functionality to share data between apps using Appcelerator Node.ACS (20)

3 Ways to Get Started with a React App in 2024.pdf
3 Ways to Get Started with a React App in 2024.pdf3 Ways to Get Started with a React App in 2024.pdf
3 Ways to Get Started with a React App in 2024.pdf
 
NodeJS @ ACS
NodeJS @ ACSNodeJS @ ACS
NodeJS @ ACS
 
Final Report To Executive ManagersXXXXXCCA 625Un
Final Report To Executive ManagersXXXXXCCA 625UnFinal Report To Executive ManagersXXXXXCCA 625Un
Final Report To Executive ManagersXXXXXCCA 625Un
 
Build Message-Based Web Services for SOA
Build Message-Based Web Services for SOABuild Message-Based Web Services for SOA
Build Message-Based Web Services for SOA
 
Tips and Tricks For Faster Asp.NET and MVC Applications
Tips and Tricks For Faster Asp.NET and MVC ApplicationsTips and Tricks For Faster Asp.NET and MVC Applications
Tips and Tricks For Faster Asp.NET and MVC Applications
 
Express node js
Express node jsExpress node js
Express node js
 
Application integration framework & Adaptor ppt
Application integration framework & Adaptor pptApplication integration framework & Adaptor ppt
Application integration framework & Adaptor ppt
 
Why use .net by naveen kumar veligeti
Why use .net by naveen kumar veligetiWhy use .net by naveen kumar veligeti
Why use .net by naveen kumar veligeti
 
ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010
ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010
ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010
 
Serverless solution architecture in AWS
Serverless solution architecture in AWSServerless solution architecture in AWS
Serverless solution architecture in AWS
 
Background Tasks with Worker Service
Background Tasks with Worker ServiceBackground Tasks with Worker Service
Background Tasks with Worker Service
 
Cloud Readiness : CAST & Microsoft Azure Partnership Overview
Cloud Readiness : CAST & Microsoft Azure Partnership OverviewCloud Readiness : CAST & Microsoft Azure Partnership Overview
Cloud Readiness : CAST & Microsoft Azure Partnership Overview
 
Web services intro.
Web services intro.Web services intro.
Web services intro.
 
Final paper
Final paperFinal paper
Final paper
 
Webservices in SalesForce (part 1)
Webservices in SalesForce (part 1)Webservices in SalesForce (part 1)
Webservices in SalesForce (part 1)
 
WebServices using Soap
WebServices using SoapWebServices using Soap
WebServices using Soap
 
SoapUi using WebServices
SoapUi using WebServicesSoapUi using WebServices
SoapUi using WebServices
 
WebServices using Soapui
WebServices using SoapuiWebServices using Soapui
WebServices using Soapui
 
Day 4 - Cloud Migration - But How?
Day 4 - Cloud Migration - But How?Day 4 - Cloud Migration - But How?
Day 4 - Cloud Migration - But How?
 
Custom connector development using mule DevKit
Custom connector development using mule DevKitCustom connector development using mule DevKit
Custom connector development using mule DevKit
 

Add server-side functionality to share data between apps using Appcelerator Node.ACS

  • 1. Appcelerator Node.ACS Adding server-side functionality to share data between apps within the Appcelerator ecosystem TiLondon Martin Hudson March 2014
  • 2. WHAT is node.js? “Node.js is a platform built on Chrome's JavaScript runtime for easily building fast, scalable network applications. Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient, perfect for data-intensive real-time applications that run across distributed devices.” nodejs.org •Appcelerator have provided an out-of-the-box service embedded directly into Titanium Studio. •Fully integrates with Appcelerator Cloud Services (ACS)
  • 3. WHy would you use it? APIs Web service endpoints Service 1 Service 2 Service 3 We want to talk to external services to retrieve information
  • 4. Why would you use it? - orchestration APIs Web service endpoints Reduce messages - each can take 0.5s to create and tear down over 3G network - then send the payload!
  • 5. WHy would you use it? - Abstraction APIs Web service endpoints Swap out 3rd party suppliers without redeploying the app Credit card process
  • 6. WHy would you use it? - integration & minification APIs Web service endpoints Simplify complex API responses into small JSON packets
  • 7. creating a node.js webservice To create a new widget, right click the project name in the Titanium Studio project view... and select New Node.ACS Service.→ Doing it this way puts ACS in the same project tree; particularly useful when using version control as your app code is synched with the webservice.
  • 8. Project file structure Doing it this way puts ACS in the same project tree; particularly useful when using version control as your app code is synched with the webservice. An ACS folder is created; we are interested in the controllers and config.js
  • 9. TESTING The service Right click the project name in the Titanium Studio project view... and select Publish Publish Node.ACS Service.→
  • 10. TESTING The service If you are sending sensitive data, change from http:// to https://. We often just publish directly to the cloud and put debugging and error info into the response stream. That way we can switch debugging on in production if something mis-behaves. In TiApp.xml you can change the location of the service from localhost to the public url of the published service. This enables you to easily test on real devices. Stay on localhost for debugging.
  • 11. Project file structure The “controllers” folder holds a file “application.js” by default; we use this to hold our web services. We can create as many controllers as we like, each containing logical groups of web services. “config.js” is used to map our web service methods to real-world urls. We also specify if the service call uses PUSH or GET.
  • 12. TESTING The service Use the public url you stored in TiApp.xml and post it into a browser; you should see the services running. the “config.js” file shows the routing for the default call to the service and points to { "path": "/", "callback": "application#index" } in the controller, “application.js” contains the method “index” function index(req, res) { res.render('index', { title: 'Welcome to Node.ACS!' }); }
  • 13. Building services To create a new service, right click the project name in the Titanium Studio project view... and select New Node.ACS Method.→
  • 14. Building services To create a new service, right click the project name in the Titanium Studio project view... and select New Node.ACS Method.→ Specify the web method name you want to expose, I’m going to create a method called “testGet”
  • 15. Building services You will see a new file “services.js” has been created and the “testGet” method added. “config.js” will also have changed, it now contains the routing to new “testGet” method. By default, the method is always set to GET.
  • 16. Building services Manually create another method “testPost” and manually modify “config.js” as well. don’t forget to change the “testPost” method from “get” to “post” in “config.js”
  • 17. passing data GET requests pass in data via. the query string POST requests pass in data via. the request body the “req” object contains the http request, we construct the response and put it into the “send” function of the “res” object. NOTE: we can simply construct the JSON response and return it.
  • 18. asynchronous methods node.js is a great, lightweight server; but you need to understand how to make the best use of it. When we make a call and it is serviced by the server, the server blocks all other incoming requests until it processes the current call. If the service is to be scalable we need to ensure that requests process quickly. For anything but the most trivial calls like the test examples we created we need to process methods asynchronously.
  • 19. configuring the client Publish the new node.js node changes into production.
  • 20. configuring the client This auto-generates the bindings that the app needs to connect to the node.js server. It puts the bindings file into the “Resources” folder. If you are developing in Alloy you will need to move it because it will be overwritten by the Alloy compiler when you next do a clean build... In the Titanium Studio project view select Node.ACS Import Node.ACS→ Bindings. and select the service we have built. Check the alloy.js file from the list and click OK
  • 21. configuring the client If you add new web services you can either repeat and rinse this process, or simply add the extra method references into bindings file. We create a “lib” folder off the root of the “app” folder and put the bindings file into it.
  • 22. configuring the client In alloy.js you will see we have created the reference to our service. Edit this to create a global we can now reference from wherever we need to.
  • 23. configuring the client If you look in the bindings file that was auto generated you will see our new web service methods.
  • 24. editing the bindings Unfortunately, the auto-generated file won’t handle get requests that have parameters in the query string. Add the following local function to the bindings file...
  • 25. editing the bindings and modify the get method to push the serialized data into the query string. Oh and remember to remove the “data” object from within “InvokeService” too...
  • 26. Testing the code Create a test harness in index.xml and index.js as follows: index.xml index.js
  • 28. Thank you Source code: http://bit.ly/1jZHJvb Slideshare: http://slidesha.re/1myDc7s check out our other slideshares: Slideshare: http://bit.ly/alloy-customTableViewSlides Mobile Data Systems Ltd.Turnkey mobile consultancy www.mobiledatasystems.co martin.hudson@mobiledatasystems.co