O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

PHP Web Services

Book Description

Whether you’re sharing data between two internal systems or building an API so users can access their data, this practical book provides everything you need to build web service APIs with PHP. Author Lorna Jane Mitchell uses code samples, real-world examples, and advice based on her extensive experience to guide you through the process—from the underlying theory to methods for making your service robust.

PHP is ideally suited for both consuming and creating web services. You’ll learn how to use this language with JSON, XML, and other web service technologies.

  • Explore HTTP, from the request/response cycle to its verbs, headers, and cookies
  • Determine whether JSON or XML is the best data format for your application
  • Get practical advice for working with RPC, SOAP, and RESTful services
  • Use a variety of tools and techniques for debugging HTTP web services
  • Choose the service that works best for your application, and learn how to make it robust
  • Learn how to document your API—and how to design it to handle errors

Table of Contents

  1. Preface
    1. Conventions Used in This Book
    2. Using Code Examples
    3. Safari® Books Online
    4. How to Contact Us
    5. Acknowledgments
  2. 1. HTTP
    1. Clients and Servers
    2. Making HTTP Requests
      1. Curl
      2. Browser Tools
      3. PHP
  3. 2. HTTP Verbs
    1. Making GET Requests
    2. Making POST Requests
    3. Using Other HTTP Verbs
  4. 3. Headers
    1. Request and Response Headers
    2. Common HTTP Headers
      1. User-Agent
      2. Headers for Content Negotiation
        1. Parsing an Accept header
        2. Demonstrating Accept headers with Curl
      3. Securing Requests with the Authorization Header
        1. HTTP basic authentication
        2. OAuth
    3. Custom Headers
  5. 4. Cookies
    1. Cookie Mechanics
    2. Working with Cookies in PHP
  6. 5. JSON
    1. When to Choose JSON
    2. Handling JSON with PHP
    3. JSON in Existing APIs
  7. 6. XML
    1. When to Choose XML
    2. XML in PHP
    3. XML in Existing APIs
  8. 7. RPC and SOAP Services
    1. RPC
    2. SOAP
      1. WSDL
      2. PHP SOAP Client
      3. PHP SOAP Server
      4. Generating a WSDL File from PHP
      5. PHP Client and Server with WSDL
  9. 8. REST
    1. RESTful URLs
    2. Resource Structure and Hypermedia
    3. Data and Media Types
    4. HTTP Features in REST
      1. Create Resources
      2. Read Records
      3. Update Records
      4. Delete Records
    5. Additional Headers in RESTful Services
      1. Authorization Headers
      2. Caching Headers
    6. RESTful versus Useful
  10. 9. Debugging Web Services
    1. Debug Output
    2. Logging
    3. Debugging from Outside Your Application
      1. Wireshark
      2. Charles Proxy
    4. Finding the Tool for the Job
  11. 10. Making Service Design Decisions
    1. Service Type Decisions
    2. Consider Data Formats
    3. Customizable Experiences
    4. Pick Your Defaults
  12. 11. Building a Robust Service
    1. Consistency Is Key
      1. Consistent and Meaningful Naming
      2. Common Validation Rules
      3. Predictable Structures
    2. Making Design Decisions for Robustness
  13. 12. Error Handling in APIs
    1. Output Format
    2. Meaningful Error Messages
    3. What to Do When You See Errors
  14. 13. Documentation
    1. Overview Documentation
    2. API Documentation
    3. Interactive Documentation
    4. Tutorials and the Wider Ecosystem
  15. A. A Guide to Common Status Codes
  16. B. Common HTTP Headers
  17. About the Author
  18. Colophon
  19. Copyright