Web Services
Examples:
- facebook
- sendgrid
- firebase
- google prediction api
- google QPX api
- stripe
- paypal
Web Services Protocols
● BEEP - Blocks Extensible Exchange Protocol
● E-Business XML
● Hessian
● JSON-RPC
● JSON-WSP
● REST - Representational State Transfer
● SOAP - outgrowth of XML-RPC, originally an acronym for Simple Object Access Protocol
● Universal Description, Discovery, and Integration (UDDI)
● Web Processing Service (WPS)
● WSFL - Web Services Flow Language (superseded by BPEL)
● WSCL - Web Services Conversation Language
● XINS Standard Calling Convention - HTTP parameters in (GET/POST/HEAD), POX out
● XLANG - XLANG-Specification (superseded by BPEL)
● XML-RPC - XML Remote Procedure Call
XMS vs JSON
<?xml version="1.0" encoding="UTF-8"?>
<bookstore>
<book category="CHILDREN">
<title>Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
<book category="WEB">
<title>Learning XML</title>
<author>Erik T. Ray</author>
<year>2003</year>
<price>39.95</price>
</book>
</bookstore>
[
{
“title”:”Harry Potter”,
“author”:”J K. Rowling”,
“category”:”CHILDREN”,
“year”:2005,
“price”:29.99
},
{
“title”:”Learning XML”,
“author”:”Erik T. Ray”,
“category”:”WEB”,
“year”:2003,
“price”:39.95
}
]
XML
pros
- extendable
- offers support for validation
- sometimes easier to understand by a human reader
- supported by more web services
cons
- huge overhead
JSON
pros
- easier to implement parsers
- faster parser
- smaller data
- works hand in hand with AJAX and JavaScript
cons
- limited data types
- can’t enforce rules between interfaces of services
- supported mostly by services that are over HTTP
var string = JSON.stringify(object);
var object = JSON.parse(string);
object.toJSON - changes the normal transformation
Example
{ "age" : 2 , “name”:”John” }
HTTP METHODS
GET
HEAD
POST
PUT
DELETE
TRACE
OPTIONS
jQuery AJAX
$.ajax({
method: "PUT",
url: "some.php",
data: { name: "John", location: "Boston" }
})
.done( function( msg ) {
alert( "Data Saved: " + msg );
} );
jQuery AJAX
$.get("URL")
.done(function(data){
//code on success
})
.fail(function(){
//code on fail
})
.always(function(){
// code called at every end of ajax request for both success and
failiure
});
$.post("URL",data)
.done(function(respose){
//code on success
})
.fail(function(){
//code on fail
})
.always(function(){
// code called at every end of ajax request for both success and
failiure
});
Further reading
- XML-RPC
- JSON-RPC
- SOAP
- WSDL (web service definition language) + SOAP binding
- ESB (Enterprise Service Bus)

Web Services and Mobile

  • 1.
  • 5.
    Examples: - facebook - sendgrid -firebase - google prediction api - google QPX api - stripe - paypal
  • 6.
    Web Services Protocols ●BEEP - Blocks Extensible Exchange Protocol ● E-Business XML ● Hessian ● JSON-RPC ● JSON-WSP ● REST - Representational State Transfer ● SOAP - outgrowth of XML-RPC, originally an acronym for Simple Object Access Protocol ● Universal Description, Discovery, and Integration (UDDI) ● Web Processing Service (WPS) ● WSFL - Web Services Flow Language (superseded by BPEL) ● WSCL - Web Services Conversation Language ● XINS Standard Calling Convention - HTTP parameters in (GET/POST/HEAD), POX out ● XLANG - XLANG-Specification (superseded by BPEL) ● XML-RPC - XML Remote Procedure Call
  • 7.
  • 8.
    <?xml version="1.0" encoding="UTF-8"?> <bookstore> <bookcategory="CHILDREN"> <title>Harry Potter</title> <author>J K. Rowling</author> <year>2005</year> <price>29.99</price> </book> <book category="WEB"> <title>Learning XML</title> <author>Erik T. Ray</author> <year>2003</year> <price>39.95</price> </book> </bookstore> [ { “title”:”Harry Potter”, “author”:”J K. Rowling”, “category”:”CHILDREN”, “year”:2005, “price”:29.99 }, { “title”:”Learning XML”, “author”:”Erik T. Ray”, “category”:”WEB”, “year”:2003, “price”:39.95 } ]
  • 9.
    XML pros - extendable - offerssupport for validation - sometimes easier to understand by a human reader - supported by more web services cons - huge overhead JSON pros - easier to implement parsers - faster parser - smaller data - works hand in hand with AJAX and JavaScript cons - limited data types - can’t enforce rules between interfaces of services - supported mostly by services that are over HTTP
  • 10.
    var string =JSON.stringify(object); var object = JSON.parse(string); object.toJSON - changes the normal transformation Example { "age" : 2 , “name”:”John” }
  • 13.
  • 15.
    jQuery AJAX $.ajax({ method: "PUT", url:"some.php", data: { name: "John", location: "Boston" } }) .done( function( msg ) { alert( "Data Saved: " + msg ); } );
  • 16.
    jQuery AJAX $.get("URL") .done(function(data){ //code onsuccess }) .fail(function(){ //code on fail }) .always(function(){ // code called at every end of ajax request for both success and failiure }); $.post("URL",data) .done(function(respose){ //code on success }) .fail(function(){ //code on fail }) .always(function(){ // code called at every end of ajax request for both success and failiure });
  • 17.
    Further reading - XML-RPC -JSON-RPC - SOAP - WSDL (web service definition language) + SOAP binding - ESB (Enterprise Service Bus)