Top Banner

of 31

Creating and Consuming Web Services in Php 51391

Apr 06, 2018

Download

Documents

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
  • 8/3/2019 Creating and Consuming Web Services in Php 51391

    1/31

    Creating and Consuming

    Web Services in PHP 5Central Florida PHP

    1

  • 8/3/2019 Creating and Consuming Web Services in Php 51391

    2/31

    Creating and Consuming

    Web Services in PHP 5

    Web Service Basics

    Using Existing Web Services

    Rolling Your Own Web Service

    2

  • 8/3/2019 Creating and Consuming Web Services in Php 51391

    3/31

    Web Service Basics

    3

  • 8/3/2019 Creating and Consuming Web Services in Php 51391

    4/31

    What are Web Services?

    According to WikiPedia Web Services are frequently just Web APIs that

    can be accessed over a network, such as theInternet, and executed on a remote systemhosting the requested services

    4

  • 8/3/2019 Creating and Consuming Web Services in Php 51391

    5/31

    What are Web Services?

    ...in fewer words

    Web Services are a way to send and receiveinformation between remote programs.

    5

  • 8/3/2019 Creating and Consuming Web Services in Php 51391

    6/31

    What are Web Services

    Good For?

    6

  • 8/3/2019 Creating and Consuming Web Services in Php 51391

    7/31

    What are Web Services

    Good For?

    Resource

    6

  • 8/3/2019 Creating and Consuming Web Services in Php 51391

    8/31

    What are Web Services

    Good For?

    Resource

    Consumer

    6

  • 8/3/2019 Creating and Consuming Web Services in Php 51391

    9/31

    What are Web Services

    Good For?

    Resource

    Consumer

    Consumer

    Consumer

    Consumer

    6

  • 8/3/2019 Creating and Consuming Web Services in Php 51391

    10/31

    What are Web Services

    Good For?

    Resource

    Consumer

    Consumer

    Consumer

    Consumer

    6

  • 8/3/2019 Creating and Consuming Web Services in Php 51391

    11/31

    What are Web Services

    Good For?

    Resource

    Consumer

    Consumer

    Consumer

    Consumer

    6

  • 8/3/2019 Creating and Consuming Web Services in Php 51391

    12/31

    What are Web Services

    Good For?

    Resource

    Consumer

    Consumer

    Consumer

    Consumer

    6

  • 8/3/2019 Creating and Consuming Web Services in Php 51391

    13/31

    What are Web Services

    Good For?

    Resource

    Consumer

    Consumer

    Consumer

    Consumer

    6

  • 8/3/2019 Creating and Consuming Web Services in Php 51391

    14/31

    What are Web Services

    Good For?

    Resource

    Consumer

    Consumer

    Consumer

    Consumer

    6

  • 8/3/2019 Creating and Consuming Web Services in Php 51391

    15/31

    Types of Web Services

    XML-RPC

    SOAP

    REST

    Free-form

    7

  • 8/3/2019 Creating and Consuming Web Services in Php 51391

    16/31

    XML-RPC

    RPC = Remote Procedure Call

    The Grandfather of XML-based RPCservices

    Hence its name

    Since 1998 A precursor to SOAP

    8

  • 8/3/2019 Creating and Consuming Web Services in Php 51391

    17/31

    XML-RPC Libraries

    http://php.net/xmlrpc/

    Native PHP support since 4.1.0 Not enabled by default

    Documentation Sucks

    http://phpxmlrpc.sourceforge.net/ Useful, Inc (Who also brought you XML-RPC)

    9

  • 8/3/2019 Creating and Consuming Web Services in Php 51391

    18/31

    XML-RPC Libraries

    http://pear.php.net/package/XML_RPC/

    The classic, tried and true library PHP 4

    Last Update 28 Oct 2006

    http://pear.php.net/package/XML_RPC2/ PHP 5 Only

    10

  • 8/3/2019 Creating and Consuming Web Services in Php 51391

    19/31

    SOAP

    Developed, Maintained, and Recommendedby W3C

    http://www.w3.org/TR/soap/

    Originally Simple Object Access Protocol

    Now it is just SOAP Probab ly because it is not very sim ple...

    11

    http://www.w3.org/TR/soap/http://www.w3.org/TR/soap/http://www.w3.org/TR/soap/
  • 8/3/2019 Creating and Consuming Web Services in Php 51391

    20/31

    SOAP + WSDL

    WSDL = Yet another W3 Standard

    Web Service Description Language http://www.w3.org/TR/wsdl/

    Used to expose SOAP web services

    SOAP w/o WSDL means more typing

    SOAP w/WSDL means less work

    12

  • 8/3/2019 Creating and Consuming Web Services in Php 51391

    21/31

    SOAP + WSDL

    WSDL = Yet another W3 Standard

    Web Service Description Language http://www.w3.org/TR/wsdl/

    Used to expose SOAP web services

    SOAP w/o WSDL means more typing

    SOAP w/WSDL means less work

    13

  • 8/3/2019 Creating and Consuming Web Services in Php 51391

    22/31

    Consuming Soap Services$clientOptions = array (

    uri => http://host/server/ ,location => http://host/server/MathServer.php

    );

    $Client = new SoapClient (NULL, $clientOptions );

    $method = add ;$params = array (

    new SoapParam (12345, number1 ),new SoapParam (98765, number2 )

    );

    echo $Client -> __call ( $method , $params );

    14

  • 8/3/2019 Creating and Consuming Web Services in Php 51391

    23/31

    SOAP Libraries

    $Client = new SoapClient (http://host/Math.wsdl);

    echo $Client -> add (1234, 5678);

    15

  • 8/3/2019 Creating and Consuming Web Services in Php 51391

    24/31

    REST

    REST = Representational State Transfer

    Isnot

    a standard ... but it does use standards

    HTTP, URI, XML

    REST puts Web back into Web Services The Internet is a REST system

    16

  • 8/3/2019 Creating and Consuming Web Services in Php 51391

    25/31

    REST + URI

    REST puts the focus back into a URI ratherthan obscuring it behind an API

    http://some-store.com/categories/

    http://some-store.com/products/widget

    http://some-store.com/search/gadgets

    17

  • 8/3/2019 Creating and Consuming Web Services in Php 51391

    26/31

    Real Life Examples

    18

  • 8/3/2019 Creating and Consuming Web Services in Php 51391

    27/31

    del.icio.us

    Most popular social bookmarking utility

    http://del.icio.us

    A property of Yahoo!

    Wicked simple REST API

    http://d el.icio.us/help/a pi/

    19

    http://del.icio.us/http://del.icio.us/http://del.icio.us/
  • 8/3/2019 Creating and Consuming Web Services in Php 51391

    28/31

    The del.icio.us API

    Update

    https://api.del.icio.us/v1/posts/update

    Tags

    https://api.del.icio.us/v1/tags/get

    https:// api.del.icio.us/v1/tags/rename

    20

    https://api.del.icio.us/v1/posts/updatehttps://api.del.icio.us/v1/tags/renamehttps://api.del.icio.us/v1/tags/renamehttps://api.del.icio.us/v1/tags/gethttps://api.del.icio.us/v1/tags/gethttps://api.del.icio.us/v1/posts/updatehttps://api.del.icio.us/v1/posts/update
  • 8/3/2019 Creating and Consuming Web Services in Php 51391

    29/31

    The del.icio.us API

    Simple API = Simple Documentation

    http://del.icio.us/help/api

    Uses HTTP Authentication

    Still under development

    21

    http://del.icio.us/help/apihttp://del.icio.us/help/apihttp://del.icio.us/help/api
  • 8/3/2019 Creating and Consuming Web Services in Php 51391

    30/31

    The del.icio.us API

    Posts

    https://api.del.icio.us/v1/posts/get

    https:// api.del.icio.us/v1/posts/recent

    https:// api.del.icio.us/v1/posts/all

    https:// api.del.icio.us/v1/posts/dates

    https:// api.del.icio.us/v1/posts/add

    https:// api.del.icio.us/v1/posts/delete

    22

    https://api.del.icio.us/v1/posts/addhttps://api.del.icio.us/v1/posts/dateshttps://api.del.icio.us/v1/posts/allhttps://api.del.icio.us/v1/posts/recenthttps://api.del.icio.us/v1/posts/gethttps://api.del.icio.us/v1/posts/deletehttps://api.del.icio.us/v1/posts/deletehttps://api.del.icio.us/v1/posts/addhttps://api.del.icio.us/v1/posts/addhttps://api.del.icio.us/v1/posts/dateshttps://api.del.icio.us/v1/posts/dateshttps://api.del.icio.us/v1/posts/allhttps://api.del.icio.us/v1/posts/allhttps://api.del.icio.us/v1/posts/recenthttps://api.del.icio.us/v1/posts/recenthttps://api.del.icio.us/v1/posts/gethttps://api.del.icio.us/v1/posts/get
  • 8/3/2019 Creating and Consuming Web Services in Php 51391

    31/31

    The del.icio.us API

    Bundles https://api.del.icio.us/v1/tags/bundles/all

    https:// api.del.icio.us/v1/tags/bundles/set

    https:// api.del.icio.us/v1/tags/bundles/delete

    https://api.del.icio.us/v1/tags/bundles/sethttps://api.del.icio.us/v1/tags/bundles/allhttps://api.del.icio.us/v1/tags/bundles/deletehttps://api.del.icio.us/v1/tags/bundles/deletehttps://api.del.icio.us/v1/tags/bundles/sethttps://api.del.icio.us/v1/tags/bundles/sethttps://api.del.icio.us/v1/tags/bundles/allhttps://api.del.icio.us/v1/tags/bundles/all