Creating Web APIs with Kaloyan Raev Zend Technologies
$ whoami Zend Studio Team Lead Eclipse committer Work @ Home Skier
Why Web APIs Web App API
Types of APIs Remote Procedure Call (RPC) REpresentational State Transfer (REST)
RPC Single URI for many operations Single HTTP method (usually POST) Structured message format (usually XML) Structured documentation (e.g. WSDL) Examples: XML-RPC, SOAP HTTP/1.1 200 OK Content-Type: text/xml <?xml version="1.0" encoding="utf-8"?> <methodResponse> <params> <param><value><struct> <member> <name>status</name> <value><string>Hello, #bgphp!</string></value> </member> <member> <name>user</name> <value><string>tosho</string></value> </member> <member> <name>timestamp></name> <value><dateTime.iso8601>20150927T11:20:00</dateTime.iso8601 </member> </struct></value></param> </params> </methodResponse>
REST URIs as unique identifier for resources Rich set of HTTP verbs for operations Flexible messaging formats negotiated with the server Hypermedia linking between resources (what can be done next)
Richardson Maturity Model
How To Get There Representations formats Error reporting Available HTTP methods Authentication and authorization Hypermedia linking Documentation
Apigility To The Rescue The world’s easiest way to create high-quality APIs Open Source Based on PHP Created by the ZF Experts: @mwop @ezimuel
Features REST and RPC services JSON (HAL) as default format Error Reporting (API Problem) HTTP Method Negotiation Content Negotiation Filtering and Validation Authentication and Authorization (HTTP Basic/Digest, OAuth2) Versioning (via URI and Accept header) Interactive Documentation (HTML, Swagger) Modular & Extensible Based on ZF2 but works with any PHP framework
Further Reading REST Service Tutorial: https://www.apigility.org/documentation/intro/first-rest-service Documentation: https://www.apigility.org/documentation Apigility and Symfony2: http://www.zimuel.it/create-api-symfony2-apigility/
Thank you! More information on apigility.org Rank me on https://joind.in/14880 Follow me on @kaloyanraev

Creating web APIs with apigility

  • 1.
    Creating Web APIs with KaloyanRaev Zend Technologies
  • 2.
    $ whoami Zend StudioTeam Lead Eclipse committer Work @ Home Skier
  • 3.
  • 4.
    Types of APIs RemoteProcedure Call (RPC) REpresentational State Transfer (REST)
  • 5.
    RPC Single URI formany operations Single HTTP method (usually POST) Structured message format (usually XML) Structured documentation (e.g. WSDL) Examples: XML-RPC, SOAP HTTP/1.1 200 OK Content-Type: text/xml <?xml version="1.0" encoding="utf-8"?> <methodResponse> <params> <param><value><struct> <member> <name>status</name> <value><string>Hello, #bgphp!</string></value> </member> <member> <name>user</name> <value><string>tosho</string></value> </member> <member> <name>timestamp></name> <value><dateTime.iso8601>20150927T11:20:00</dateTime.iso8601 </member> </struct></value></param> </params> </methodResponse>
  • 6.
    REST URIs as uniqueidentifier for resources Rich set of HTTP verbs for operations Flexible messaging formats negotiated with the server Hypermedia linking between resources (what can be done next)
  • 7.
  • 8.
    How To GetThere Representations formats Error reporting Available HTTP methods Authentication and authorization Hypermedia linking Documentation
  • 9.
    Apigility To TheRescue The world’s easiest way to create high-quality APIs Open Source Based on PHP Created by the ZF Experts: @mwop @ezimuel
  • 10.
    Features REST and RPCservices JSON (HAL) as default format Error Reporting (API Problem) HTTP Method Negotiation Content Negotiation Filtering and Validation Authentication and Authorization (HTTP Basic/Digest, OAuth2) Versioning (via URI and Accept header) Interactive Documentation (HTML, Swagger) Modular & Extensible Based on ZF2 but works with any PHP framework
  • 12.
    Further Reading REST ServiceTutorial: https://www.apigility.org/documentation/intro/first-rest-service Documentation: https://www.apigility.org/documentation Apigility and Symfony2: http://www.zimuel.it/create-api-symfony2-apigility/
  • 13.
    Thank you! More informationon apigility.org Rank me on https://joind.in/14880 Follow me on @kaloyanraev

Editor's Notes

  • #9 What representation formats will you expose? How will you report that you cannot fulfill a request for a given representation? REST does not dictate any specific formats. How will you report errors? Again, REST does not dictate any specific error reporting format, beyond suggesting that appropriate HTTP response codes should be used; however, these alone do not provide enough detail to be useful for consumers. How will you advertise which HTTP methods are available for a given resource? What will you do if the consumer uses a request method you do not support? How will you handle features such as authentication? Web APIs are generally stateless, and should not rely on features such as session cookies; how will the consumer provide their credentials on each request? Will you use HTTP authentication, or OAuth2, or create API tokens? How will you handle hypermedia linking? Some formats, such as XML, essentially have linking built-in; others, such as JSON, have no native format, which means you need to choose how you will provide links. How will you document what resources are available? Unlike RPC, there are no "built-in" mechanisms for describing REST services; while hypermedia linking will assist, the consumer still needs to know the various entry points for your API. These are not trivial questions, and in many cases, the choices you make for one will impact the choices you make for another. In a nutshell, most REST provides incredible flexibility and power, but requires you to make many choices in order to provide a solid, quality experience for consumers.