Web Services REST

From Training Material
Revision as of 21:16, 25 September 2021 by Lsokolowski (talk | contribs) (→‎Exercises)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search


title
Web Services Basics For Non-programmers
author
Pete George (NobleProg Ltd)

Day Two Schedule ⌘

  1. WSDL
  2. Handling Binary Content
  3. RESTfull Web Services
  4. Other Technologies
  5. 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 ⌘

REST 1.png

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 ⌘

REST 2.png

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 ⌘

REST 3.png

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 ⌘

REST 4.png

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:

REST 5.png

A RESTful Web Service Example ⌘

Create HTTP Request

REST 6.png

A RESTful Web Service Example ⌘

Create HTTP Header Manager

REST 7.png

A RESTful Web Service Example ⌘

Run JMeter and view results in JSON

REST 8.png

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 ⌘

REST 9.png

Why JSON and Web Services? ⌘

  • Easily readable

REST 10.png

Less Performance Impact ⌘

REST 11.png

JSON Standards ⌘

  • JSON Schemas are available
  • Standards not as developed as XML/SOAP
  • www.json.org promotes spread of JSON

Quiz – No Prizes! No Pressure! ⌘

REST 13.png

Exercises

REST API Exercises