Web services soap and rest by mandakini for TechGig

3,317 views
2,992 views

Published on

WS serves as an interface to software developers.
Using WS as an API you can convert applications into web-applications.
WS is the vision of ‘Future Internet’
The basic Web services platform is XML + HTTP.
WS is future for Mobile application

Published in: Technology
2 Comments
3 Likes
Statistics
Notes
No Downloads
Views
Total views
3,317
On SlideShare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
227
Comments
2
Likes
3
Embeds 0
No embeds

No notes for slide

Web services soap and rest by mandakini for TechGig

  1. 1. Mandakini Kumari June 15th 2012
  2. 2. Who am I Have 9 + years of experience in open source specially PHP, Drupal & Web Services. Active crusader to improve effectiveness and reach of Free & Open Source Software(FOSS). Impart industrial consultancy for best use of software application. Frequently conduct training for students and industrial experts.
  3. 3. What am I going to talk about ? Use of Web Services ? What is Web Services Different Ways: SOAP & REST SOAP Vs REST How am I going to use REST Example: Twitter, Paypal
  4. 4. Use of Web Services(WS) Payment Gateway integration for E-commerce site. Google Map for a Real Estate Site. Product detail for a price comparison website Weather forecast for a news or blog site Mashup: Combine data from one or more source and integrate application
  5. 5. Payment Gateway integration http://paypal.com
  6. 6. Why WS for Payment getaway Very Fast Very Reliable Secure User don’t know what getway used by the site User don’t need to register on payment site e.g. paypal Website Administration is very easy e.g. IRCT with netbanking ICICI
  7. 7. Google Map Web services for your website
  8. 8. Top APIs for Mashups http://programmableweb.com/apis
  9. 9. What is Web Services(WS) WS serves as an interface to software developers. Using WS as an API you can convert applications into web-applications. WS is the vision of ‘Future Internet’ The basic Web services platform is XML + HTTP. WS is future for Mobile application
  10. 10. What is SOAP SOAP is a simple XML-based protocol to let applications exchange information over HTTP Businesses can register their WS on UDDI(Universal Description, Discovery and Integration) and provide documentation with WSDL (Web Services Description Language). SOAP is mostly used for Enterprise applications to integrate wide types and another trend is to integrate with legacy systems
  11. 11. SOAP Architecture
  12. 12. SOAP Building Blocks
  13. 13. Paypal SOAP Building Blocks
  14. 14. A SOAP Envelope <?xml version="1.0"?> <soap:Envelope xmlns:soap="http://www.w3.org/2001/12/soap-envelope" soap:encodingStyle="http://www.w3.org/2001/12/soap- encoding"> .... </soap:Envelope>
  15. 15. SOAP Header Element <SOAP-ENV:Header> <RequesterCredentials xmlns=”urn:ebay:api:PayPalAPI” xsi:type=”ebl:CustomSecurityHeaderType”> <Credentials xmlns=”urn:ebay:apis:eBLBaseComponents” xsi:type=”ebl:UserIdPasswordType”> <Username>api_username</Username> <Password>api_password</Password> <Signature>api_signature</Signature> <Subject>authorizing_account_emailaddress</Subject> </Credentials> </RequesterCredentials> </SOAP-ENV:Header>
  16. 16. SOAP Body Request Element <soap:Body> <m:GetPrice mlns:m="http://www.example.com/prices"> <m:Item>Laptop</m:Item> </m:GetPrice> </soap:Body>
  17. 17. A SOAP Response HTTP/1.1 200 OK Content-Type: application/soap+xml; charset=utf-8 Content-Length: nnn <?xml version="1.0"?> <soap:Envelope xmlns:soap="http://www.w3.org/2001/12/soap-envelope" soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding"> <soap:Body> <m:GetPriceResponse xmlns:m="http://www.example.com/prices"> <m:Price>$900</m:Price> </m:GetPriceResponse> </soap:Body> </soap:Envelope>
  18. 18. PHP SOAP Server Example$server = new SoapServer("Library.wsdl",array("classmap"=>$classmap));$server->addFunction("searchAuthors");$server->addFunction("searchBooks");$server->handle();
  19. 19. PHP SOAP Client Example$client=new SoapClient("http://localhost/Library.wsdl",array("trace" => 1));try{ //$response = $client->searchAuthors("Beh"); $response = $client->searchBooks("te");var_dump($response);echo htmlspecialchars($client->__getLastRequest())."";echo htmlspecialchars($client->__getLastResponse())."";}catch(Exception $e){ var_dump($e); echo $client->__getLastRequest();echo $client->__getLastResponse();}
  20. 20. RESTful Web services Representational State Transfer (REST) has gained widespread acceptance across the Web REST permits many different data formats HTTP consists in URIs, methods, status codes … REST is great for clean, simple, robust services REST is a software architecture style used in developing stateless web services REST is an acronym standing for Representational State Transfer.
  21. 21. Architecture of REST
  22. 22. RESTful Web Service HTTP methods HTTP CRUD SQL POST Create INSERT GET Read SELECT PUT Update UPDATE DELETE Delete DELETE
  23. 23. Data Format Supported By REST xml – almost any programming language can read XML json – useful for JavaScript and increasingly PHP apps. csv – open with spreadsheet programs html – a simple HTML table php – Representation of PHP code that can be eval()’ed serialize – Serialized data that can be unserialized in PHP
  24. 24. Different Methods to Interact with REST  file_get_contents()  cURL  SimpleXml
  25. 25. 1) File_get_contents()<?php$result = file_get_contents(http:// twitter .com/users/show/screenname);var_dump($result);HTTP Basic authentication you can use the following syntax to get data from your password protected RESTful AP$user = json_decode( file_get_contents(http://admin:1234@example.com/index.php/api/use r/id/1/format/json));echo $user->name;
  26. 26. REST from PHP: GET(CURL)<?php$ch = curl_init(http://twitter.com/users);curl_exec($ch);
  27. 27. REST from PHP: DELETE<?php$ch = curl_init(http://example.com/users/ginny);curl_setopt($ch, CURLOPT_CUSTOMREQUEST, DELETE);curl_exec($ch);
  28. 28. Soap Vs Rest
  29. 29. Why REST /1 Creating clients, developing APIs, and understanding documentation is much easier in REST than SOAP REST permits many different data formats where as SOAP only permits XML JSON is a better fit for data and parses very faster REST allows better support for browser clients due to it’s support for JSON REST reads can be cached, SOAP based reads cannot be cached. REST has better performance and scalability.
  30. 30. Why SOAP /2 WS-Security: SOAP supports SSL (just like REST) it also supports WS-Security which adds some enterprise security features. WS-AtomicTransaction: Need ACID Transactions over a service then you need SOAP. While REST supports transactions, it isn’t as comprehensive and isn’t ACID compliant WS-ReliableMessaging: Rest doesn’t have a standard messaging system and expects clients to deal with communication failures by retrying. SOAP has successful/retry logic built in and provides end-to-end reliability even through SOAP intermediaries.
  31. 31. SOAP Vs REST /3 In Summary, SOAP is clearly useful, and important. For instance, if I was writing an iPhone application to interface with my bank I would definitely need to use SOAP. All three features above are required for banking transactions. For example, if I was transferring money from one account to the other, I would need to be certain that it completed. Retrying it could be catastrophic if it succeed the first time, but the response failed.
  32. 32. Questions ???
  33. 33. ThankyouMandakini Kumarihttps://www.facebook.com/mandakini.kumarihttp://www.slideshare.net/mandakinikumarihttp://www.linkedin.com/pub/mandakini-kumari/18/93/935

×