SlideShare une entreprise Scribd logo
1  sur  35
Initial setup
• Install postman
https://www.getpostman.com/
• Download workshop materials
• Install nodejs https://nodejs.org/en/
• Github repo  http://bit.ly/2cMeCm1
• Signup for PP
– https://www.paypal.com/signup/account
• Postman collection http://bit.ly/2dkWFwj
NTU Workshop: Using REST APIs
Aeshan Wijetunge
Developer@PayPal
Objectives
• Appreciate the benefits of leveraging public
APIs
• Understand basics of calling a REST APIs
• Can make payments using the PayPal API
• Understand the benefits of Asynchronous
programming
• Create a mashup of PayPal APIs leverging the
Async library
What is a REST API?
• REpresentational State Transfer
• Context of Web Services
• URLs (e.g:
https://api.github.com/users/aeshanw)
• Interface to Resources over the Internet
Credit: http://www.robert-drummond.com/
Simple Example
Credit: Salesforce https://developer.salesforce.com/page/REST_API
Being RESTful
• APIs are Resource-centric
• REST is built-atop the HTTP protocol
• HTTP is the infrastructure of the Internet
• REST APIs (a.k.a web services) support
– GET
– POST
– PUT
– DELETE
Anatomy of HTTP
Credits: http://cis.msjc.edu/ Mt San Jacinto College
Calling a simple API
• Fetch github user details
• https://api.github.com/users/aeshanw
• Response can be viewed on a web browser
• This is a GET operation
• What about POST/PUT/DELETE?
– We need a more advanced tool to work with REST
APIs
Introducing POSTMAN
• Tool for working with REST APIs
• As a developer you can
– Customize the HTTP Headers of request
– Authenticate your requests to protected APIs
• Supports Oauth for this purpose
Using POSTMAN
• Import the POSTMAN collection:
– https://www.getpostman.com/collections/b0038e
d98853ba7e1b10
• Call the github URI with POSTMAN
• Note the status code and response headers
PayPal APIs
• A huge collection of APIs handling
– Payments
– Invoicing
– Billing Agreements
• Our focus will be on
– Storing a credit card on the Vault API
– Making a payment with the Vaulted card
PayPal Secured by OAuth
• Similar to log-in with username & password
• You need a PayPal account (personal)
• Authenticate via v1/oauth2/token API
• Get your clientID & secret
• POSTMAN Authorization tab
– Select `Basic Auth` Type
– Username  clientID
– Password  secret
Authenticating your requests
v1/oauth2/token
v1/vault/credit-
cards
/v1/payments/pa
yment
clientID + secret AccessToken
AccessToken
Add credit card
• Using /v1/vault/credit-cards
• Request Body is in a JSON-format
• Request Headers include the AccessToken
credit cards for testing
• PayPal sandbox is for testing only
• Allows use of dummy cards for testing
• Use this site for generating credit card
numbers for testing
• http://www.freeformatter.com/credit-card-
number-generator-validator.html
Pay with a Vaulted card
v1/oauth2/token
v1/vault/credit-cards
v1/payments/payment
AccessToken
CardToken
PaymentID
Try this in POSTMAN
• Use the POSTMAN collection provided earlier
• Use POSTMAN global variables to store the
AccessToken to be used in subsequent
requests
• Exercise
– Get Token (Authenticate)
– Add a card to vault
– Make a payment with the vaulted card
Getting started with Node.js
• Let’s make the calls from our application
• Using node.js as an example, but concepts
valid in any language.
• Exercise : Run the node.js app locally
– $ npm install
– $ npm start
– Goto http://localhost:8000/
API calls from node.js
• Use the request module as REST
Clienthttps://www.npmjs.com/package/reque
st
• Look for Lab 1.0a in
demoapp/controllers/index.js
Optimization
• What if you need to add several cards at
once?
addCard1 payWithCard1 addCard2 payWithCard2
• Is there a faster way?
• Yes, Parallelization
Going in Synch
• Java Synchronous example
Now in Async
• Javascript example
Asynchronous Complexity
• Many languages support Asynchronous
libraries. E.g: Python, Java, Javascript, Scala,
Erlang…
• But, Developing code that is Asynchronous
can be difficult.
• Thankfully most modern languages provide
libraries to manage the complexity
• Async is popular among Javascript developers
Using Async
• Docs here
https://www.npmjs.com/package/async
• Async can execute your code
– In series
– In parallel
Async series
• Call the APIs in sequence one after the other
• Run nodeserv dummy service to better
understand the difference
– $ cd nodeserv
– $ npm install
– $ node index.js
• Look for Lab 1.1a in
demoapp/controllers/index.js
Async series workshop
• Nodeserv has a 5 sec time-delay to simulate
I/O latency
• How long would this lab code take to call the
task API twice?
Async parallel
• Call the APIs in parallel
• Look for Lab 1.1b in
demoapp/controllers/index.js
• Did you notice any difference in the time
taken to call the API twice?
PayPal Integration
• Let’s integrate the vaulted-card solution into
our node.js application
• First, we need to get the access_token
• Look for Lab 2.0 in
demoapp/controllers/index.js
• Test the api-call by hitting
localhost:8000/gettoken
• Ensure you get the access_token
Vault the card
• Pass the access_token to a funtion which adds
the card to vault
• Look for Lab 2.1 in
demoapp/controllers/index.js
• Ensure you get the card_token from the vault
API response
• Test the api-call by hitting
localhost:8000/addcard
Make Payment
• Use case: We need to split a big payment into
2 credit cards due to some credit-limits on
each card
• Parallelize the vaulting of 2 cards
• Parallelize the 2 payments using the card
tokens
• Look for Lab 2.2 in
demoapp/controllers/index.js
Fix the code
• Fix the payment api call in payWithToken
• Parallelize the functions addCardToVault &
payWithToken in order to complete the tasks
as efficiently as possible.
• Test the calls by hitting
localhost:8000/paywithvault
– Check the logs to verify the result
Bonus lab (optional)
• Notice that the Card Tokens are logged to
console
• Can we lookup the Vaulted Card details?
• Lookup the PayPal Vault API to do this
Recap
• Appreciate the use of APIs in applications
• Call a RESTful API using POSTMAN
• Call a RESTful API from an application
• Debug API Integrations using logs
• Parallelize API calls with Async libraries
Beyond Javascript
• Many languages support Async
– Python
– Java
So what’s stopping you from using it in your
next application? 
Thanks!
• https://github.com/nodeworkshop/ntu_2016
_async_workshop
• PP Sample Cards
• https://www.paypalobjects.com/en_US/vhelp
/paypalmanager_help/credit_card_numbers.h
tm

Contenu connexe

Tendances

You are not_hiding_from_me_.net
You are not_hiding_from_me_.netYou are not_hiding_from_me_.net
You are not_hiding_from_me_.netChung Wee Jing
 
DDD Melbourne 2014 security in ASP.Net Web API 2
DDD Melbourne 2014 security in ASP.Net Web API 2DDD Melbourne 2014 security in ASP.Net Web API 2
DDD Melbourne 2014 security in ASP.Net Web API 2Pratik Khasnabis
 
Laravel 5 Annotations: RESTful API routing
Laravel 5 Annotations: RESTful API routingLaravel 5 Annotations: RESTful API routing
Laravel 5 Annotations: RESTful API routingChristopher Pecoraro
 
An Introduction to the Laravel Framework (AFUP Forum PHP 2014)
An Introduction to the Laravel Framework (AFUP Forum PHP 2014)An Introduction to the Laravel Framework (AFUP Forum PHP 2014)
An Introduction to the Laravel Framework (AFUP Forum PHP 2014)daylerees
 
Amazon Web Service - Basics
Amazon Web Service - BasicsAmazon Web Service - Basics
Amazon Web Service - BasicsSang-Min Park
 
Microsoft Exchange Best Practices: Tips for Setup, Maintenance and Room Resou...
Microsoft Exchange Best Practices: Tips for Setup, Maintenance and Room Resou...Microsoft Exchange Best Practices: Tips for Setup, Maintenance and Room Resou...
Microsoft Exchange Best Practices: Tips for Setup, Maintenance and Room Resou...Teem
 
SP24S053 Introduction to PowerShell for SharePoint Developers and Administrators
SP24S053 Introduction to PowerShell for SharePoint Developers and AdministratorsSP24S053 Introduction to PowerShell for SharePoint Developers and Administrators
SP24S053 Introduction to PowerShell for SharePoint Developers and AdministratorsMichael Blumenthal (Microsoft MVP)
 
Laravel introduction
Laravel introductionLaravel introduction
Laravel introductionSimon Funk
 
API Development with Laravel
API Development with LaravelAPI Development with Laravel
API Development with LaravelMichael Peacock
 
Cooking your Ravioli "al dente" with Hexagonal Architecture
Cooking your Ravioli "al dente" with Hexagonal ArchitectureCooking your Ravioli "al dente" with Hexagonal Architecture
Cooking your Ravioli "al dente" with Hexagonal ArchitectureJeroen Rosenberg
 
What's new in Rails 5 - API Mode & Action Cable overview
What's new in Rails 5 - API Mode & Action Cable overviewWhat's new in Rails 5 - API Mode & Action Cable overview
What's new in Rails 5 - API Mode & Action Cable overviewMaxim Veksler
 
Rails antipatterns
Rails antipatternsRails antipatterns
Rails antipatternsChul Ju Hong
 
Rails antipattern-public
Rails antipattern-publicRails antipattern-public
Rails antipattern-publicChul Ju Hong
 
SymfonyCon Cluj 2017 - Symfony at OpenSky
SymfonyCon Cluj 2017 - Symfony at OpenSkySymfonyCon Cluj 2017 - Symfony at OpenSky
SymfonyCon Cluj 2017 - Symfony at OpenSkyPablo Godel
 
Intro To Serverless ClojureScript
Intro To Serverless ClojureScriptIntro To Serverless ClojureScript
Intro To Serverless ClojureScriptJim Lynch
 
Using Apache Camel as AKKA
Using Apache Camel as AKKAUsing Apache Camel as AKKA
Using Apache Camel as AKKAJohan Edstrom
 

Tendances (20)

You are not_hiding_from_me_.net
You are not_hiding_from_me_.netYou are not_hiding_from_me_.net
You are not_hiding_from_me_.net
 
Laravel Introduction
Laravel IntroductionLaravel Introduction
Laravel Introduction
 
DDD Melbourne 2014 security in ASP.Net Web API 2
DDD Melbourne 2014 security in ASP.Net Web API 2DDD Melbourne 2014 security in ASP.Net Web API 2
DDD Melbourne 2014 security in ASP.Net Web API 2
 
Laravel 5 Annotations: RESTful API routing
Laravel 5 Annotations: RESTful API routingLaravel 5 Annotations: RESTful API routing
Laravel 5 Annotations: RESTful API routing
 
An Introduction to the Laravel Framework (AFUP Forum PHP 2014)
An Introduction to the Laravel Framework (AFUP Forum PHP 2014)An Introduction to the Laravel Framework (AFUP Forum PHP 2014)
An Introduction to the Laravel Framework (AFUP Forum PHP 2014)
 
Amazon Web Service - Basics
Amazon Web Service - BasicsAmazon Web Service - Basics
Amazon Web Service - Basics
 
Microsoft Exchange Best Practices: Tips for Setup, Maintenance and Room Resou...
Microsoft Exchange Best Practices: Tips for Setup, Maintenance and Room Resou...Microsoft Exchange Best Practices: Tips for Setup, Maintenance and Room Resou...
Microsoft Exchange Best Practices: Tips for Setup, Maintenance and Room Resou...
 
SP24S053 Introduction to PowerShell for SharePoint Developers and Administrators
SP24S053 Introduction to PowerShell for SharePoint Developers and AdministratorsSP24S053 Introduction to PowerShell for SharePoint Developers and Administrators
SP24S053 Introduction to PowerShell for SharePoint Developers and Administrators
 
Rack
RackRack
Rack
 
Laravel introduction
Laravel introductionLaravel introduction
Laravel introduction
 
API Development with Laravel
API Development with LaravelAPI Development with Laravel
API Development with Laravel
 
Cooking your Ravioli "al dente" with Hexagonal Architecture
Cooking your Ravioli "al dente" with Hexagonal ArchitectureCooking your Ravioli "al dente" with Hexagonal Architecture
Cooking your Ravioli "al dente" with Hexagonal Architecture
 
What's new in Rails 5 - API Mode & Action Cable overview
What's new in Rails 5 - API Mode & Action Cable overviewWhat's new in Rails 5 - API Mode & Action Cable overview
What's new in Rails 5 - API Mode & Action Cable overview
 
Rails antipatterns
Rails antipatternsRails antipatterns
Rails antipatterns
 
Rails antipattern-public
Rails antipattern-publicRails antipattern-public
Rails antipattern-public
 
Why akka
Why akkaWhy akka
Why akka
 
SymfonyCon Cluj 2017 - Symfony at OpenSky
SymfonyCon Cluj 2017 - Symfony at OpenSkySymfonyCon Cluj 2017 - Symfony at OpenSky
SymfonyCon Cluj 2017 - Symfony at OpenSky
 
Laravel 5
Laravel 5Laravel 5
Laravel 5
 
Intro To Serverless ClojureScript
Intro To Serverless ClojureScriptIntro To Serverless ClojureScript
Intro To Serverless ClojureScript
 
Using Apache Camel as AKKA
Using Apache Camel as AKKAUsing Apache Camel as AKKA
Using Apache Camel as AKKA
 

En vedette

Webinar Online Learning Myths & Engaging (Distance) Learners!
Webinar Online Learning Myths & Engaging (Distance) Learners!Webinar Online Learning Myths & Engaging (Distance) Learners!
Webinar Online Learning Myths & Engaging (Distance) Learners!Sara Valla
 
Autocad Draftsman
Autocad DraftsmanAutocad Draftsman
Autocad Draftsmanjubin alby
 
Work Experience
Work ExperienceWork Experience
Work Experiencepnimmag1
 
Human Sensitivity In Forced Feedback Systems (07 31 2009 02 28 18)
Human Sensitivity In Forced Feedback Systems (07 31 2009 02 28 18)Human Sensitivity In Forced Feedback Systems (07 31 2009 02 28 18)
Human Sensitivity In Forced Feedback Systems (07 31 2009 02 28 18)pnimmag1
 
Understanding REST APIs in 5 Simple Steps
Understanding REST APIs in 5 Simple StepsUnderstanding REST APIs in 5 Simple Steps
Understanding REST APIs in 5 Simple StepsTessa Mero
 
Modernize Service-Oriented Architecture with APIs
Modernize Service-Oriented Architecture with APIsModernize Service-Oriented Architecture with APIs
Modernize Service-Oriented Architecture with APIsApigee | Google Cloud
 
ESB vs API management
ESB vs API managementESB vs API management
ESB vs API managementAdroitLogic
 

En vedette (10)

Webinar Online Learning Myths & Engaging (Distance) Learners!
Webinar Online Learning Myths & Engaging (Distance) Learners!Webinar Online Learning Myths & Engaging (Distance) Learners!
Webinar Online Learning Myths & Engaging (Distance) Learners!
 
Autocad Draftsman
Autocad DraftsmanAutocad Draftsman
Autocad Draftsman
 
Prueba saber
Prueba saberPrueba saber
Prueba saber
 
1
11
1
 
Work Experience
Work ExperienceWork Experience
Work Experience
 
Human Sensitivity In Forced Feedback Systems (07 31 2009 02 28 18)
Human Sensitivity In Forced Feedback Systems (07 31 2009 02 28 18)Human Sensitivity In Forced Feedback Systems (07 31 2009 02 28 18)
Human Sensitivity In Forced Feedback Systems (07 31 2009 02 28 18)
 
Que son comandos
Que son comandosQue son comandos
Que son comandos
 
Understanding REST APIs in 5 Simple Steps
Understanding REST APIs in 5 Simple StepsUnderstanding REST APIs in 5 Simple Steps
Understanding REST APIs in 5 Simple Steps
 
Modernize Service-Oriented Architecture with APIs
Modernize Service-Oriented Architecture with APIsModernize Service-Oriented Architecture with APIs
Modernize Service-Oriented Architecture with APIs
 
ESB vs API management
ESB vs API managementESB vs API management
ESB vs API management
 

Similaire à Ntu workshop : REST, PayPal APIs & Async

Adaptive Payments SDK - Magento Developers Paradise
Adaptive Payments SDK - Magento Developers ParadiseAdaptive Payments SDK - Magento Developers Paradise
Adaptive Payments SDK - Magento Developers ParadisePayPal
 
HTTP Services & REST API Security
HTTP Services & REST API SecurityHTTP Services & REST API Security
HTTP Services & REST API SecurityTaiseer Joudeh
 
An introduction to the API for OnTime for IBM
An introduction to the API for OnTime for IBMAn introduction to the API for OnTime for IBM
An introduction to the API for OnTime for IBMontimesuite
 
Building Awesome APIs with Lumen
Building Awesome APIs with LumenBuilding Awesome APIs with Lumen
Building Awesome APIs with LumenKit Brennan
 
Build and Manage Your APIs with Amazon API Gateway
Build and Manage Your APIs with Amazon API GatewayBuild and Manage Your APIs with Amazon API Gateway
Build and Manage Your APIs with Amazon API GatewayAmazon Web Services
 
Migrate your Existing Express Apps to AWS Lambda and Amazon API Gateway
Migrate your Existing Express Apps to AWS Lambda and Amazon API GatewayMigrate your Existing Express Apps to AWS Lambda and Amazon API Gateway
Migrate your Existing Express Apps to AWS Lambda and Amazon API GatewayAmazon Web Services
 
WAC Network APIs @ OverTheAir 2011
WAC Network APIs @ OverTheAir 2011WAC Network APIs @ OverTheAir 2011
WAC Network APIs @ OverTheAir 2011Ricardo Varela
 
Distributed app development with nodejs and zeromq
Distributed app development with nodejs and zeromqDistributed app development with nodejs and zeromq
Distributed app development with nodejs and zeromqRuben Tan
 
Build and Manage Your APIs with Amazon API Gateway
Build and Manage Your APIs with Amazon API GatewayBuild and Manage Your APIs with Amazon API Gateway
Build and Manage Your APIs with Amazon API GatewayAmazon Web Services
 
Advanced Postman for Better APIs - Web Summit 2018 - Cisco DevNet
Advanced Postman for Better APIs - Web Summit 2018 - Cisco DevNetAdvanced Postman for Better APIs - Web Summit 2018 - Cisco DevNet
Advanced Postman for Better APIs - Web Summit 2018 - Cisco DevNetCisco DevNet
 
POST/CON 2019 Workshop: Testing, Automated Testing, and Reporting APIs with P...
POST/CON 2019 Workshop: Testing, Automated Testing, and Reporting APIs with P...POST/CON 2019 Workshop: Testing, Automated Testing, and Reporting APIs with P...
POST/CON 2019 Workshop: Testing, Automated Testing, and Reporting APIs with P...Postman
 
Enjoying the Move from WCF to the Web API
Enjoying the Move from WCF to the Web APIEnjoying the Move from WCF to the Web API
Enjoying the Move from WCF to the Web APIKevin Hazzard
 
Parallel and Asynchronous Programming - ITProDevConnections 2012 (English)
Parallel and Asynchronous Programming -  ITProDevConnections 2012 (English)Parallel and Asynchronous Programming -  ITProDevConnections 2012 (English)
Parallel and Asynchronous Programming - ITProDevConnections 2012 (English)Panagiotis Kanavos
 
SPUnite17 Timer Jobs Event Handlers
SPUnite17 Timer Jobs Event HandlersSPUnite17 Timer Jobs Event Handlers
SPUnite17 Timer Jobs Event HandlersNCCOMMS
 
Introduction to Ethereum
Introduction to EthereumIntroduction to Ethereum
Introduction to EthereumArnold Pham
 
Scaling Rails With Torquebox Presented at JUDCon:2011 Boston
Scaling Rails With Torquebox Presented at JUDCon:2011 BostonScaling Rails With Torquebox Presented at JUDCon:2011 Boston
Scaling Rails With Torquebox Presented at JUDCon:2011 Bostonbenbrowning
 

Similaire à Ntu workshop : REST, PayPal APIs & Async (20)

Adaptive Payments SDK - Magento Developers Paradise
Adaptive Payments SDK - Magento Developers ParadiseAdaptive Payments SDK - Magento Developers Paradise
Adaptive Payments SDK - Magento Developers Paradise
 
Amazon API Gateway
Amazon API GatewayAmazon API Gateway
Amazon API Gateway
 
HTTP Services & REST API Security
HTTP Services & REST API SecurityHTTP Services & REST API Security
HTTP Services & REST API Security
 
An introduction to the API for OnTime for IBM
An introduction to the API for OnTime for IBMAn introduction to the API for OnTime for IBM
An introduction to the API for OnTime for IBM
 
REST APIs
REST APIsREST APIs
REST APIs
 
Building Awesome APIs with Lumen
Building Awesome APIs with LumenBuilding Awesome APIs with Lumen
Building Awesome APIs with Lumen
 
Build and Manage Your APIs with Amazon API Gateway
Build and Manage Your APIs with Amazon API GatewayBuild and Manage Your APIs with Amazon API Gateway
Build and Manage Your APIs with Amazon API Gateway
 
Windows 8 Metro apps and the outside world
Windows 8 Metro apps and the outside worldWindows 8 Metro apps and the outside world
Windows 8 Metro apps and the outside world
 
Migrate your Existing Express Apps to AWS Lambda and Amazon API Gateway
Migrate your Existing Express Apps to AWS Lambda and Amazon API GatewayMigrate your Existing Express Apps to AWS Lambda and Amazon API Gateway
Migrate your Existing Express Apps to AWS Lambda and Amazon API Gateway
 
WAC Network APIs @ OverTheAir 2011
WAC Network APIs @ OverTheAir 2011WAC Network APIs @ OverTheAir 2011
WAC Network APIs @ OverTheAir 2011
 
Distributed app development with nodejs and zeromq
Distributed app development with nodejs and zeromqDistributed app development with nodejs and zeromq
Distributed app development with nodejs and zeromq
 
Build and Manage Your APIs with Amazon API Gateway
Build and Manage Your APIs with Amazon API GatewayBuild and Manage Your APIs with Amazon API Gateway
Build and Manage Your APIs with Amazon API Gateway
 
Operating your Production API
Operating your Production APIOperating your Production API
Operating your Production API
 
Advanced Postman for Better APIs - Web Summit 2018 - Cisco DevNet
Advanced Postman for Better APIs - Web Summit 2018 - Cisco DevNetAdvanced Postman for Better APIs - Web Summit 2018 - Cisco DevNet
Advanced Postman for Better APIs - Web Summit 2018 - Cisco DevNet
 
POST/CON 2019 Workshop: Testing, Automated Testing, and Reporting APIs with P...
POST/CON 2019 Workshop: Testing, Automated Testing, and Reporting APIs with P...POST/CON 2019 Workshop: Testing, Automated Testing, and Reporting APIs with P...
POST/CON 2019 Workshop: Testing, Automated Testing, and Reporting APIs with P...
 
Enjoying the Move from WCF to the Web API
Enjoying the Move from WCF to the Web APIEnjoying the Move from WCF to the Web API
Enjoying the Move from WCF to the Web API
 
Parallel and Asynchronous Programming - ITProDevConnections 2012 (English)
Parallel and Asynchronous Programming -  ITProDevConnections 2012 (English)Parallel and Asynchronous Programming -  ITProDevConnections 2012 (English)
Parallel and Asynchronous Programming - ITProDevConnections 2012 (English)
 
SPUnite17 Timer Jobs Event Handlers
SPUnite17 Timer Jobs Event HandlersSPUnite17 Timer Jobs Event Handlers
SPUnite17 Timer Jobs Event Handlers
 
Introduction to Ethereum
Introduction to EthereumIntroduction to Ethereum
Introduction to Ethereum
 
Scaling Rails With Torquebox Presented at JUDCon:2011 Boston
Scaling Rails With Torquebox Presented at JUDCon:2011 BostonScaling Rails With Torquebox Presented at JUDCon:2011 Boston
Scaling Rails With Torquebox Presented at JUDCon:2011 Boston
 

Dernier

Top 10 Interactive Website Design Trends in 2024.pptx
Top 10 Interactive Website Design Trends in 2024.pptxTop 10 Interactive Website Design Trends in 2024.pptx
Top 10 Interactive Website Design Trends in 2024.pptxDyna Gilbert
 
Unidad 4 – Redes de ordenadores (en inglés).pptx
Unidad 4 – Redes de ordenadores (en inglés).pptxUnidad 4 – Redes de ordenadores (en inglés).pptx
Unidad 4 – Redes de ordenadores (en inglés).pptxmibuzondetrabajo
 
TRENDS Enabling and inhibiting dimensions.pptx
TRENDS Enabling and inhibiting dimensions.pptxTRENDS Enabling and inhibiting dimensions.pptx
TRENDS Enabling and inhibiting dimensions.pptxAndrieCagasanAkio
 
『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书
『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书
『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书rnrncn29
 
ETHICAL HACKING dddddddddddddddfnandni.pptx
ETHICAL HACKING dddddddddddddddfnandni.pptxETHICAL HACKING dddddddddddddddfnandni.pptx
ETHICAL HACKING dddddddddddddddfnandni.pptxNIMMANAGANTI RAMAKRISHNA
 
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书rnrncn29
 
IP addressing and IPv6, presented by Paul Wilson at IETF 119
IP addressing and IPv6, presented by Paul Wilson at IETF 119IP addressing and IPv6, presented by Paul Wilson at IETF 119
IP addressing and IPv6, presented by Paul Wilson at IETF 119APNIC
 
Company Snapshot Theme for Business by Slidesgo.pptx
Company Snapshot Theme for Business by Slidesgo.pptxCompany Snapshot Theme for Business by Slidesgo.pptx
Company Snapshot Theme for Business by Slidesgo.pptxMario
 
SCM Symposium PPT Format Customer loyalty is predi
SCM Symposium PPT Format Customer loyalty is prediSCM Symposium PPT Format Customer loyalty is predi
SCM Symposium PPT Format Customer loyalty is predieusebiomeyer
 
Film cover research (1).pptxsdasdasdasdasdasa
Film cover research (1).pptxsdasdasdasdasdasaFilm cover research (1).pptxsdasdasdasdasdasa
Film cover research (1).pptxsdasdasdasdasdasa494f574xmv
 
办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书
办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书
办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书zdzoqco
 

Dernier (11)

Top 10 Interactive Website Design Trends in 2024.pptx
Top 10 Interactive Website Design Trends in 2024.pptxTop 10 Interactive Website Design Trends in 2024.pptx
Top 10 Interactive Website Design Trends in 2024.pptx
 
Unidad 4 – Redes de ordenadores (en inglés).pptx
Unidad 4 – Redes de ordenadores (en inglés).pptxUnidad 4 – Redes de ordenadores (en inglés).pptx
Unidad 4 – Redes de ordenadores (en inglés).pptx
 
TRENDS Enabling and inhibiting dimensions.pptx
TRENDS Enabling and inhibiting dimensions.pptxTRENDS Enabling and inhibiting dimensions.pptx
TRENDS Enabling and inhibiting dimensions.pptx
 
『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书
『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书
『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书
 
ETHICAL HACKING dddddddddddddddfnandni.pptx
ETHICAL HACKING dddddddddddddddfnandni.pptxETHICAL HACKING dddddddddddddddfnandni.pptx
ETHICAL HACKING dddddddddddddddfnandni.pptx
 
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书
 
IP addressing and IPv6, presented by Paul Wilson at IETF 119
IP addressing and IPv6, presented by Paul Wilson at IETF 119IP addressing and IPv6, presented by Paul Wilson at IETF 119
IP addressing and IPv6, presented by Paul Wilson at IETF 119
 
Company Snapshot Theme for Business by Slidesgo.pptx
Company Snapshot Theme for Business by Slidesgo.pptxCompany Snapshot Theme for Business by Slidesgo.pptx
Company Snapshot Theme for Business by Slidesgo.pptx
 
SCM Symposium PPT Format Customer loyalty is predi
SCM Symposium PPT Format Customer loyalty is prediSCM Symposium PPT Format Customer loyalty is predi
SCM Symposium PPT Format Customer loyalty is predi
 
Film cover research (1).pptxsdasdasdasdasdasa
Film cover research (1).pptxsdasdasdasdasdasaFilm cover research (1).pptxsdasdasdasdasdasa
Film cover research (1).pptxsdasdasdasdasdasa
 
办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书
办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书
办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书
 

Ntu workshop : REST, PayPal APIs & Async

  • 1. Initial setup • Install postman https://www.getpostman.com/ • Download workshop materials • Install nodejs https://nodejs.org/en/ • Github repo  http://bit.ly/2cMeCm1 • Signup for PP – https://www.paypal.com/signup/account • Postman collection http://bit.ly/2dkWFwj
  • 2. NTU Workshop: Using REST APIs Aeshan Wijetunge Developer@PayPal
  • 3. Objectives • Appreciate the benefits of leveraging public APIs • Understand basics of calling a REST APIs • Can make payments using the PayPal API • Understand the benefits of Asynchronous programming • Create a mashup of PayPal APIs leverging the Async library
  • 4. What is a REST API? • REpresentational State Transfer • Context of Web Services • URLs (e.g: https://api.github.com/users/aeshanw) • Interface to Resources over the Internet Credit: http://www.robert-drummond.com/
  • 5. Simple Example Credit: Salesforce https://developer.salesforce.com/page/REST_API
  • 6. Being RESTful • APIs are Resource-centric • REST is built-atop the HTTP protocol • HTTP is the infrastructure of the Internet • REST APIs (a.k.a web services) support – GET – POST – PUT – DELETE
  • 7. Anatomy of HTTP Credits: http://cis.msjc.edu/ Mt San Jacinto College
  • 8. Calling a simple API • Fetch github user details • https://api.github.com/users/aeshanw • Response can be viewed on a web browser • This is a GET operation • What about POST/PUT/DELETE? – We need a more advanced tool to work with REST APIs
  • 9. Introducing POSTMAN • Tool for working with REST APIs • As a developer you can – Customize the HTTP Headers of request – Authenticate your requests to protected APIs • Supports Oauth for this purpose
  • 10. Using POSTMAN • Import the POSTMAN collection: – https://www.getpostman.com/collections/b0038e d98853ba7e1b10 • Call the github URI with POSTMAN • Note the status code and response headers
  • 11. PayPal APIs • A huge collection of APIs handling – Payments – Invoicing – Billing Agreements • Our focus will be on – Storing a credit card on the Vault API – Making a payment with the Vaulted card
  • 12. PayPal Secured by OAuth • Similar to log-in with username & password • You need a PayPal account (personal) • Authenticate via v1/oauth2/token API • Get your clientID & secret • POSTMAN Authorization tab – Select `Basic Auth` Type – Username  clientID – Password  secret
  • 14. Add credit card • Using /v1/vault/credit-cards • Request Body is in a JSON-format • Request Headers include the AccessToken
  • 15. credit cards for testing • PayPal sandbox is for testing only • Allows use of dummy cards for testing • Use this site for generating credit card numbers for testing • http://www.freeformatter.com/credit-card- number-generator-validator.html
  • 16. Pay with a Vaulted card v1/oauth2/token v1/vault/credit-cards v1/payments/payment AccessToken CardToken PaymentID
  • 17. Try this in POSTMAN • Use the POSTMAN collection provided earlier • Use POSTMAN global variables to store the AccessToken to be used in subsequent requests • Exercise – Get Token (Authenticate) – Add a card to vault – Make a payment with the vaulted card
  • 18. Getting started with Node.js • Let’s make the calls from our application • Using node.js as an example, but concepts valid in any language. • Exercise : Run the node.js app locally – $ npm install – $ npm start – Goto http://localhost:8000/
  • 19. API calls from node.js • Use the request module as REST Clienthttps://www.npmjs.com/package/reque st • Look for Lab 1.0a in demoapp/controllers/index.js
  • 20. Optimization • What if you need to add several cards at once? addCard1 payWithCard1 addCard2 payWithCard2 • Is there a faster way? • Yes, Parallelization
  • 21. Going in Synch • Java Synchronous example
  • 22. Now in Async • Javascript example
  • 23. Asynchronous Complexity • Many languages support Asynchronous libraries. E.g: Python, Java, Javascript, Scala, Erlang… • But, Developing code that is Asynchronous can be difficult. • Thankfully most modern languages provide libraries to manage the complexity • Async is popular among Javascript developers
  • 24. Using Async • Docs here https://www.npmjs.com/package/async • Async can execute your code – In series – In parallel
  • 25. Async series • Call the APIs in sequence one after the other • Run nodeserv dummy service to better understand the difference – $ cd nodeserv – $ npm install – $ node index.js • Look for Lab 1.1a in demoapp/controllers/index.js
  • 26. Async series workshop • Nodeserv has a 5 sec time-delay to simulate I/O latency • How long would this lab code take to call the task API twice?
  • 27. Async parallel • Call the APIs in parallel • Look for Lab 1.1b in demoapp/controllers/index.js • Did you notice any difference in the time taken to call the API twice?
  • 28. PayPal Integration • Let’s integrate the vaulted-card solution into our node.js application • First, we need to get the access_token • Look for Lab 2.0 in demoapp/controllers/index.js • Test the api-call by hitting localhost:8000/gettoken • Ensure you get the access_token
  • 29. Vault the card • Pass the access_token to a funtion which adds the card to vault • Look for Lab 2.1 in demoapp/controllers/index.js • Ensure you get the card_token from the vault API response • Test the api-call by hitting localhost:8000/addcard
  • 30. Make Payment • Use case: We need to split a big payment into 2 credit cards due to some credit-limits on each card • Parallelize the vaulting of 2 cards • Parallelize the 2 payments using the card tokens • Look for Lab 2.2 in demoapp/controllers/index.js
  • 31. Fix the code • Fix the payment api call in payWithToken • Parallelize the functions addCardToVault & payWithToken in order to complete the tasks as efficiently as possible. • Test the calls by hitting localhost:8000/paywithvault – Check the logs to verify the result
  • 32. Bonus lab (optional) • Notice that the Card Tokens are logged to console • Can we lookup the Vaulted Card details? • Lookup the PayPal Vault API to do this
  • 33. Recap • Appreciate the use of APIs in applications • Call a RESTful API using POSTMAN • Call a RESTful API from an application • Debug API Integrations using logs • Parallelize API calls with Async libraries
  • 34. Beyond Javascript • Many languages support Async – Python – Java So what’s stopping you from using it in your next application? 
  • 35. Thanks! • https://github.com/nodeworkshop/ntu_2016 _async_workshop • PP Sample Cards • https://www.paypalobjects.com/en_US/vhelp /paypalmanager_help/credit_card_numbers.h tm

Notes de l'éditeur

  1. Quite a common process in the traditional sequential manner of execution is most basic programs
  2. addTask doesn’t wait for the response before calling the 2nd addTask Question: which response gets back first? Can you guess which prints first?