Understanding and testing RESTful Web Services - Created by Mark Winteringham / @2bittester © 2016

Understanding and testing RESTful Web Services

What makes a Web Service RESTful?

Available at http://mwtestconsultancy.co.uk/presentations/understanding_web_service/

About me...

- www.mwtestconsultancy.co.uk

- @2bittester

- linkedin.com/in/markwinteringham

profile.png

RESTful? Constraints

Stateless

Each request should contain all the neccesary information and each response should contain all session state data

Cacheable

Service consumers can cache and reuse response message data

Uniform Interface

Service consumers and services share a common, overarching, generic technical contract

Client-Server

Solution logic is separated into consumer and service logic that share a technical contract

Layered System

A solution can be comprised of multiple architectural layers

Code on Demand

Service consumers support the execution of deferred service logic

http://whatisrest.com/rest_constraints/index

Richardson Maturity Model

Level 3:Hypermedia Controls
Level 2:HTTP Verbs
Level 1:Resources
Level 0:Swamp of POX

http://martinfowler.com/articles/richardsonMaturityModel.html

Swamp of POX

web server
POST /bookings
Response




  "booking": {
    "firstname": "Sally",
    "lastname": "Brown",
    "totalprice": 111,
    "depositpaid": true,
    "bookingdates": {
      "checkin": "2013-02-23",
      "checkout": "2014-10-23"
    }
  }




  "bookings" : [
    {
      "bookingid": 1,
      "bookingdetails": {
        ...
      }
    },{
      "bookingid": 2,
      "bookingdetails": {
        ...
      }
    },{
      "bookingid": 3,
      "bookingdetails": {
        ...
      }
    }
  ]
Level 3:Hypermedia Controls
Level 2:HTTP Verbs
Level 1:Resources
Level 0:Swamp of POX

Resources

web server
POST /booking/2
Response




  "booking": {
    "firstname": "Sally",
    "lastname": "Brown",
    "totalprice": 111,
    "depositpaid": true,
    "bookingdates": {
      "checkin": "2013-02-23",
      "checkout": "2014-10-23"
    }
  }







  {
    "bookingid": 2,
    "bookingdetails": {
      "firstname": "Sally",
      "lastname": "Brown",
      "totalprice": 111,
      "depositpaid": true,
      "bookingdates": {
        "checkin": "2013-02-23",
        "checkout": "2014-10-23"
      }
  }


Level 3:Hypermedia Controls
Level 2:HTTP Verbs
Level 1:Resources
Level 0:Swamp of POX

HTTP Verbs

Create

=

POST

Read

=

GET

Update

=

PUT

Delete

=

DELETE

Level 3:Hypermedia Controls
Level 2:HTTP Verbs
Level 1:Resources
Level 0:Swamp of POX

Without Hypermedia Controls

<bookings>
  <bookingid>1</bookingid>
  <bookingid>2</bookingid>
  <bookingid>3</bookingid>
  <bookingid>4</bookingid>
  <bookingid>5</bookingid>
  <bookingid>6</bookingid>
  <bookingid>7</bookingid>
  <bookingid>8</bookingid>
</bookings>
P A R S E
<ul>
  <li>
    <a href='http://localhost:3001/booking/1'>
      Booking
    </a>
  </li>
  <li>
    <a href='http://localhost:3001/booking/2'>
      Booking
    </a>
  </li>
</ul>

With Hypermedia Controls

<bookings>
  <booking>
    <id>1</id>
    <link>
      <rel>self</rel>
      <href>http://localhost:3001/booking/1</href>
    </link>
  </booking>
	<booking>
    <id>2</id>
    <link>
      <rel>self</rel>
      <href>http://localhost:3001/booking/2</href>
    </link>
  </booking>
</bookings>
<ul>
  <li>
    <a href='http://localhost:3001/booking/1'>
      Booking
    </a>
  </li>
  <li>
    <a href='http://localhost:3001/booking/2'>
      Booking
    </a>
  </li>
</ul>

Thank you

Slides - http://mwtestconsultancy.co.uk/presentations/understanding_web_service/