RESTful Web Services

  1. Overview
    1. A web service is an API that can be invoked remotely via HTTP. Informally, a web service is a web program whose response is intended for another program rather than a human
    2. Web services often make use of XML or JSON for transmitting data in requests and responses
    3. Light weight services (sometimes called RESTful) generally require you to have some a priori knowledge about how the service is used and how to interpret its response
    4. More complicated services follow certain protocols (e.g., SOAP) and may provide their own description of how they work (e.g., WSDL)
    5. Many freely available web services allow access to large amounts of data or proprietary data
    6. General architecture
      1) Client ---------> Web Server 
                                       API Req
      2) Client            Web Server ---------> Service Provider 
      3) Client            Web Server <--------- Service Provider 
      4) Client <--------- Web Server            Service Provider 
    7. Or client directly accesses service from web server or service provider using JSONP
                 API Req
      1) Client ---------> Web Server / Service Provider 
      2) Client <--------- Web Server / Service Provider 
  2. RESTful web services
    1. REpresentational State Transfer
      1. A service represents a resource that can be accessed from the web
      2. Commonly makes use of different HTTP request methods to implement CRUD functions:
        1. POSTCreate new resource
        2. GETRetrieve resource
        3. PUTUpdate resource
        4. DELETEDelete resource
      3. Also makes use of other HTTP mechanisms: the query string, path info, etc.
      4. Requests are stateless; there is no session, so the server (usually) doesn't know what requests came before the current request
    2. Creating
      1. Web services are often created with ASP.NET Web API, Java using JAX-RS or Spring, and with Express
      2. These services can be consumed with JavaScript like jQuery or AngularJS on the client, or they may be used on the server with ASP.NET, PHP, or other server-side technology
    3. Testing
      1. Web browsers can issue GET requests easily, but other verbs are more difficult to use
      2. curl is a popular command-line tool for Linux which allows you to craft HTTP requests
      3. PostMan - REST Client is a popular Chrome add-on for making HTTP requests