Web Services REST
Day Two Schedule ⌘
- WSDL
- Handling Binary Content
- RESTfull Web Services
- Other Technologies
- Conclusion
RESTful Web Services ⌘
Learning Objectives
- To appreciate the REST style
- To understand the principles of RESTful Web services
- To understand the structure of JSON
- To understand the benefits of using JSON in Web services
RESTful Web Services ⌘
- Web services based on REST principles
- Alternative to SOAP/WSDL
- Growing in popularity
- Implemented using XML and JSON
REST ⌘
- Representational State Transfer
- Style of architecture
- Asserts principles for how networked resources are defined and addressed
WWW Based on REST ⌘
Uniform Resource Identifier (URI) ⌘
- String that points to a resource
- Can be:
-URL = Uniform Resource Locator
-E.g. http://www.facebook.com
Resource ⌘
- Anything that can be pointed to by a URI
- Examples:
-Webpage
-Location on server that processes web forms
WWW Based on REST ⌘
Hypertext Transfer Protocol (HTTP) ⌘
- Transport protocol
- Uniform Interface
-i.e. request methods and meaning are fixed
-Get, Post, Put, etc
- NB: REST is not limited to HTTP
-(although developed alongside HTTP)
WWW Based on REST ⌘
Representations ⌘
- HTML document is a “representation” of the resource, i.e. webpage
- Encapsulates the information
-State
-Data
-Markup
- Type of representation designated by media type
-E.g. text/html
-(HTTP is an implementation of the REST style)
WWW Based on REST ⌘
Hypermedia ⌘
- HTML is hypermedia format
-i.e. provides links to browse through application
- Browser “discovers” different parts of the website application through links
-Doesn’t need prior knowledge of application
-Unlike SOA – fixed interface shared through, e.g. WSDL
- User changes state of application by selecting links
-“Hypermedia as the engine of application state”
RESTful Web Services ⌘
- A Web API
-Works by REST principles
-Uses HTTP
- Four features
-the base URI for the web API
-Internet media type -Operations supported by the web API
-Hypertext driven
A RESTful Web Service Example ⌘
- A simple RESTful Web service at:
URI = http://jmeterbook.aws.af.cm/person/list
- resource = list
- HTTP Get request to get list of persons
- Media type = application/json
(data in json format)
A RESTful Web Service Example ⌘
Create JMeter Test Plan:
A RESTful Web Service Example ⌘
Create HTTP Request
A RESTful Web Service Example ⌘
Create HTTP Header Manager
A RESTful Web Service Example ⌘
Run JMeter and view results in JSON
JSON ⌘
- RESTful Web services often use JSON for data exchange
(also use XML)
- Open standard data format
- Presents data as name:value pairs in a human readable text, e.g.
“Name” : “Value”
JavaScript Object Notation ⌘
- Originally derived from JavaScript
- Language-independent
- Available in many languages
JSON Example ⌘
Response from /person/list: { "id":46, "firstName":"Pete", "jobs": [ { "id":5, "description":"Singer" } ], "lastName":"George" },
JSON Exercise ⌘
Using Jmeter:
- Create a new HTTP Request to add a person to the list
- Need to Post to /person/save resource
Why JSON and Web Services? ⌘
- Easy to use
- Resilience
- Easily readable
- Better performance (low overhead)
Easy to Use ⌘
Basic Conventions: [] List of objects
{} An object
“key”:”value” string values of an object defined under a key
“key”:value integer values of an object defined under a key
JSON Resilience ⌘
Why JSON and Web Services? ⌘
- Easily readable
Less Performance Impact ⌘
JSON Standards ⌘
- JSON Schemas are available
- Standards not as developed as XML/SOAP
- www.json.org promotes spread of JSON