Chapter 4 - RESTFUL architecture
The Web materials and resources of Chapter 4 are listed here.
Chapter 4, RESTFUL architecture
Chapter 4 REST Architecture introduces the concepts related to the programmable Web, shows how HTTP and Web services are related to each other, introduces the principles behind REST Architectural Style, explains how HTTP verbs are used in REST applications and explains the need for RESTFul web services. By the end of this chapter, students will learn the core architectural elements that form a RESTful system and will get introduced to some frameworks and tools that can be used to implement and test RESTful Web services.
Before lecture
📚 ToRead
Objectives : Understanding HTTP protocol - Understanding REST Architecture principles - learning how to implement RESTful Web services.
- From Web Service Implementation and Composition Techniques 1st ed. 2017 Edition, springer
- Chap 3. Web Services – REST or Restful Services
- From Master Php 7, 2017
- Chap 11. Building Services (Working with REST section)
- From RESTful Java Web Services, 2017, 3rd ed.
- Chap 5. Introducing the REST Architectural Style
- From Building RESTful Web Services with PHP 7 ed. 2017
- Chap 1. RESTful Web Services, Introduction and Motivation.
- From PhP web services, second edition, 2016
- Chap 1. HTTP
- Chap 2. HTTP Verbs
- Chap 3. Headers
- Chap 5. JSON
- Chap 6. XML
- Chap 8. REST
- Chap 9. HTTP Tools
- Architectural Styles and the Design of Network-based Software Architectures, by Roy Fielding PhD Thesis, University of California, Irvine, 2000
📝 ToDo The objective of this section, is to explore frameworks and tools required to build RESTFUL Web services. Design guidelines that developers will find useful while building RESTful web services are also given.
Running lecture demos:
In order to implement RESTful Web services, you will need:
- A
service container: to deploy and publish the service. We will use apache. - An
HTTP library: to handle service HTTP-based invocations. We will use Curl and PHP’s built-in stream-handling functionality. - A
JSON formatting tool: to encode and decode service data to be sent/received in the body of an HTTP request/response. We will use PHP classes. - An
XML library: To parse XML, serialize and deserialize service data to be sent/received in the body of an HTTP request/response. We will use DOM and simpleXML. APIs frameworksto implement and handle restful services requests and responses. We will use PHP extensions.
Web services examples of this course are deployed in Apache, and are written in Php.
To run demo Web services provided with this lecture, you need first to clone the following repository on your machine:TODO/REST.
Then, you need the following tools installed :
-
MAMP, WAMP, XMPP or LAMP software stack.
-
PHP’s cURL extension : PhP has its own wrappers for cURL. cURL allows to make any web request imaginable in any form, repeat those requests, and observe in detail exactly what information is exchanged between client and server. It is a brilliant, quick tool for inspecting what’s going on with a Web request, particularly when dealing with something that isn’t in a browser or where you need to be more specific about how the request is made. PhP’s cURL extension has excellent and comprehensive documentation on http://php.net. We can use this extension to make all kinds of HTTP requests, including sending custom headers, sending body data, and using different verbs to make our request. The PHP cURL extension isn’t the easiest interface to use, although it does have the advantage of being reliably available.
-
PHP’s built-in stream-handling functionality : Another great way of making HTTP requests that is always available in PHP is to use PHP’s stream-handling abilities with the file functions. In its simplest form, this means that, if
allow_url_fopenis enabled (see the PHP manual), it is possible to make requests usingfile_get_contents(). The simplest example is making aGETrequest and reading the response body in as if it were a local file. Using the PHPfile_get_contents()function, we can read files or API data but can not perform write, update, delete operations. Use cURL methods to perform all those operations using API data. - These chrome extensions with added-value :
- JSON formatter : beautifies JSON data with advanced formatting and validation algorithms.
- Network Sniffer : network traffic analyser to capture HTTP requests/responses.
-
POSTMAN : is an API client that makes it easy for developers to create, share, test and document APIs. This is done by allowing users to create and save simple and complex HTTP/s requests, as well as read their responses. It is a great tool when trying to dissect RESTful APIs made by others or test ones you have made yourself. It offers a user interface with which to make HTML requests to test an API’s functionality.
-
POSTMAN Console : To see the actual HTTP request traffic that is being sent and received in the application. In some cases, you might discover APIs that are not even documented. Postman Console allows to see and capture this network traffic easily.
- SOAPUI the open source version: an API (SOAP/REST) testing tool. SOAPUI allows to generate Restful service code from service URI and service WADL(web application description language) resources documentation. For further explanation, see https://www.soapui.org/docs/rest-testing/.
Testing others Web services implementation platforms :
Every programming language has one or several APIs to implement RESTFUL Web services that support HTTP/REST based communication. for this ToDo4 section, you are highly advised to do the following Lab exercises, to get familiarized with implementing Web services in PHP, JAVA and .NET.
-
Implementing RESTFUL web services in JAVA: Java community defines standard REST support via JAX-RS (the Java API for RESTful Web Services) in JSR 311. There are a few implementations of this standard available now (e.g., Apache CXF, RESTEasy by JBoss, Jersey by Sun). JAX-RS is a technology for building web services and clients that communicate using JSON/XML.
-Apache CXF: is an open source services framework. CXF helps you build and develop services using frontend programming APIs, like JAX-WS (SOAP) and JAX-RS (REST). These services can speak a variety of protocols such as SOAP, XML/HTTP, RESTful HTTP, or CORBA and work over a variety of transports such as HTTP, JMS or JBI.
-
Practical Exercises :
-
Lab Exercise 01: Create a web API with ASP.NET Core.
-
Lab Exercise 02: Build RESTful Service in Java using JAX-RS and Jersey (Celsius to Fahrenheit & Fahrenheit to Celsius).
-
Lab Exercise 03: A Simple REST Service with Apache CXF (JAX-RS) from Web Service Implementation and Composition Techniques 1st ed. 2017 Edition, springer.
-
After lecture :
đź’» ToCode
The objective of this ToCode4 section is to manipulate two (2) RESTFUL Web services : RWS1 and RWS2 :
RWS1: is a RESTFUL Web service you have to implement yourself.RWS2: is a RESTFUL Web service you have to choose from internet; you can for instance try Covid19 APIS, test it, then, write one client againstRWS2:Client1.
Step 1
Search for a RWS2 : it should support REST-based invocation.
Testing :
- TEST the web service with SOAPUI (choose a method with XML response) and generate WADL file.
- TEST the web service with postman (choose a method with JSON response) and capture HTTP traffic.
- Write
Client1for a method with XML response : the one tested with SOAPUI. You can use SimpleXML to parse XML. - Write
Client2for a method with JSON response : the one tested with POSTMAN.
Step 2
Implement a RESTFUL Web service – we will call it RWS1.
- Write a PHP Web service using CURL library. Your web service should implement at least one HTTP method. Test your web service with POSTMAN or SOAPUI and generate a
WADLfile for it. - Write a client in PHP to your Web service.
Step 3 (Bonus Step)
Call RWS1 and RWS2 using a Web interface.
Step 4 (Bonus Step)
Implement a RESTFUL web service in Java or .NET and write a client for this Web service in PHP.
What to submit ?
-Create a folder and name it ToCode4. Create six(6) subfolders and name them : RWS1, RWS2, client1, client2, interface, and bonus.
-
Store the source code, of the WS and the client of each WS. Add tests and HTTP traffic capture of your
RWS1andRWS2(print screens). -
Store the source code of the interface in
interfacewith print screens of its execution interface with results. You may add an explanatory description of each web service method. -
Push your
ToCode4to yourGITrepository. -
Send the following on Microsoft Teams : Link of your git repository, print screens of the various POSTMAN/SOAPUI tests.
Additional resources :
Several RESTFUL Web services directories :