HTTP, AJAX and REST How HTTP and Web Services Work? SoftUni Team Technical Trainers Software University

Slides:



Advertisements
Similar presentations
Web Service Testing RESTful Web Services Snejina Lazarova Dimo Mitev
Advertisements

What are Web Services? How to use them?
TCP/IP Protocol Suite 1 Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 22 World Wide Web and HTTP.
With jQuery and AJAX Doncho Minkov Telerik Corporation Technical Trainer.
How the web works: HTTP and CGI explained
World Wide Web1 Applications World Wide Web. 2 Introduction What is hypertext model? Use of hypertext in World Wide Web (WWW) – HTML. WWW client-server.
The World Wide Web and the Internet Dr Jim Briggs 1WUCM1.
1 The HyperText Transfer Protocol: HTTP Nick Smith Stuart Alley Tara Tjaden.
HTTP Overview Vijayan Sugumaran School of Business Administration Oakland University.
2/9/2004 Web and HTTP February 9, /9/2004 Assignments Due – Reading and Warmup Work on Message of the Day.
Rensselaer Polytechnic Institute CSC-432 – Operating Systems David Goldschmidt, Ph.D.
With jQuery and AJAX Doncho Minkov Telerik Corporation Technical Trainer.
INTRODUCTION TO WEB DATABASE PROGRAMMING
Computer Concepts 2014 Chapter 7 The Web and .
Web Architecture Dr. Frank McCown Intro to Web Science Harding University This work is licensed under a Creative Commons Attribution-NonCommercial- ShareAlike.
1 HTML and CGI Scripting CSC8304 – Computing Environments for Bioinformatics - Lecture 10.
SUNY Polytechnic Institute CS 490 – Web Design, AJAX, jQuery Web Services A web service is a software system that supports interaction (requesting data,
Copyright © cs-tutorial.com. Introduction to Web Development In 1990 and 1991,Tim Berners-Lee created the World Wide Web at the European Laboratory for.
WWW, HTTP, AJAX, JSONP Nikolay Kostov Telerik Software Academy Senior Software Developer and Trainer
FTP (File Transfer Protocol) & Telnet
HyperText Transfer Protocol (HTTP).  HTTP is the protocol that supports communication between web browsers and web servers.  A “Web Server” is a HTTP.
27.1 Chapter 27 WWW and HTTP Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
CP476 Internet Computing Lecture 5 : HTTP, WWW and URL 1 Lecture 5. WWW, HTTP and URL Objective: to review the concepts of WWW to understand how HTTP works.
TCP/IP Protocol Suite 1 Chapter 22 Upon completion you will be able to: World Wide Web: HTTP Understand the components of a browser and a server Understand.
JavaScript, Fourth Edition Chapter 12 Updating Web Pages with AJAX.
Maryam Elahi University of Calgary – CPSC 441.  HTTP stands for Hypertext Transfer Protocol.  Used to deliver virtually all files and other data (collectively.
Copyright (c) 2010, Dr. Kuanchin Chen1 The Client-Server Architecture of the WWW Dr. Kuanchin Chen.
AngularJS Routing Routes, Route Parameters, Templates, Location, Navigation SoftUni Team Technical Trainers Software University
AngularJS Services Built-in and Custom Services SoftUni Team Technical Trainers Software University
WWW, HTTP, GET, POST, Cookies Svetlin Nakov Telerik Corporation
The HTTP Protocol HTTP, Requests, Responses, Forms, MIME, Caching, Redirects SoftUni Team Technical Trainers Software University
World Wide Web (WWW) A Distributed Document- Based System Group E Ricky Tong (D-A0-1611) Eddy Leong (D-A0-1623) Dick Lei (D-A0-1658)
1 Welcome to CSC 301 Web Programming Charles Frank.
HTTP1 Hypertext Transfer Protocol (HTTP) After this lecture, you should be able to:  Know how Web Browsers and Web Servers communicate via HTTP Protocol.
WWW, HTTP, AJAX, JSONP Learning & Development Team Telerik Software Academy.
World Wide Web “WWW”, "Web" or "W3". World Wide Web “WWW”, "Web" or "W3"
Part 2 – WWW and HTTP Nikolay Kostov Telerik Corporation
Sessions and Cookies State Management, Cookies, Sessions, Hidden Fields SoftUni Team Technical Trainers Software University
1 WWW. 2 World Wide Web Major application protocol used on the Internet Simple interface Two concepts –Point –Click.
Operating Systems Lesson 12. HTTP vs HTML HTML: hypertext markup language ◦ Definitions of tags that are added to Web documents to control their appearance.
IS-907 Java EE World Wide Web - Overview. World Wide Web - History Tim Berners-Lee, CERN, 1990 Enable researchers to share information: Remote Access.
CITA 310 Section 2 HTTP (Selected Topics from Textbook Chapter 6)
Web Technologies Lecture 1 The Internet and HTTP.
HTTP Here, we examine the hypertext transfer protocol (http) – originally introduced around 1990 but not standardized until 1997 (version 1.0) – protocol.
27.1 Chapter 27 WWW and HTTP Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
27.1 Chapter 27 WWW and HTTP Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Internet Applications (Cont’d) Basic Internet Applications – World Wide Web (WWW) Browser Architecture Static Documents Dynamic Documents Active Documents.
CS 6401 The World Wide Web Outline Background Structure Protocols.
RESTful Web Services What is RESTful?
Overview of Servlets and JSP
COMP2322 Lab 2 HTTP Steven Lee Jan. 29, HTTP Hypertext Transfer Protocol Web’s application layer protocol Client/server model – Client (browser):
WWW and HTTP Nikolay Kostov Telerik Software Academy Senior Software Developer and Trainer
JavaScript Tools Tools for Writing / Editing / Debugging JavaScript Code Svetlin Nakov Technical Trainer Software University
27.1 Chapter 27 WWW and HTTP Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Simple Web Services. Internet Basics The Internet is based on a communication protocol named TCP (Transmission Control Protocol) TCP allows programs running.
JavaScript, Sixth Edition Chapter 11 Updating Web Pages with Ajax.
Web Storage and Cookies Cookies, Local and Session Storage SoftUni Team Technical Trainers Software University
DOM, jQuery, AJAX, REST Using Kinvey as JS Back-End
National College of Science & Information Technology.
1 Chapter 1 INTRODUCTION TO WEB. 2 Objectives In this chapter, you will: Become familiar with the architecture of the World Wide Web Learn about communication.
HTML Forms, HTTP Request & HTTP Response
Web API - Introduction AJAX, Spring Data REST SoftUni Team Web API
HTTP – An overview.
Chapter 27 WWW and HTTP Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Web Technologies HTTP, Servers, Clients SoftUni Team
HTTP, RESTful Web Services, HTTP and REST Tools: Postman, Fiddler
CISC103 Web Development Basics: Web site:
WEB API.
Presentation transcript:

HTTP, AJAX and REST How HTTP and Web Services Work? SoftUni Team Technical Trainers Software University

2  World Wide Web (WWW)  Uniform Resource Locator (URL)  The HTTP Protocol  HTTP Messages  MIME Types  Status Codes  HTML, XML, JSON, RSS  Web Services  AJAX  Same Origin Policy  Web Developer Tools Table of Contents

World Wide Web What is WWW?

4 World Wide Web  WWW = World Wide Web = Web != Internet  The Internet is a global system of interconnected computer networks  WWW is one of the services transferred over these networks  Global distributed information system in Internet (like , DNS,...)  Consists of set of documents (and other resources)  They are located on different Internet servers  Accessed through standard protocols (like HTTP, HTTPS, FTP) by URL  Web servers  Web servers provide Web content  Web browsers  Web browsers display the Web content What is WWW?

5  Structural components  Internet – provides data transfer channels over the TCP and HTTP  Clients (Web browsers) – display Web content  Web servers – IIS, Apache, Tomcat, GWS, etc.  Semantic components  Hyper Text Transfer Protocol (HTTP)  Hyper Text Markup Language (HTML)  Uniform Resource Locator (URL)  Uniform Resource Identifiers (URIs) WWW Components

6  The entire WWW system runs over standard networking protocols  TCP, HTTP, FTP, SMTP…  The HTTP protocol is fundamental for WWW  Clients use Web browser to request resources from the Web servers via HTTP  Resources have unique URL address  Servers send the requested resource as a response  Web pages are resources in WWW  HTML text, graphics, animations and other files WWW Infrastructure

URL Uniform Resource Locator

8  Uniform Resource Locator (URL)  URL is a formatted string, consisting of:  Protocol for communicating ( http, ftp, https...)  Host or IP address ( softuni.bg, gmail.com )  Port (default port is 80)  Path can be dynamic or static ( /forum, /path/ index.php )  Query string ( ?id=27&lang=en )  Fragment – Only used on the client to navigate to some section URL Scheme HostPortPathQuery Fragment

9  URLs are encoded according RFC 1738 :  Safe URL characters – [0-9a-zA-Z] $-_.+*'(),!  All other characters are escaped with the formula:  Space can also be encoded as " + " URL Encoding %[character hex code in ISO-Latin character set] ASCII CharacterURL encoding space%20 !%21 "%22 #%23 $%24 %25 &%26

10  Some valid URLs:  Some invalid URLs: URL – Examples 8&rlz=1T4GGLL_enBG369BG369&q=http+get+vs+post 1%80%D0%BD%D0%B0_%D0%B0%D0%BA%D0%B0%D0%B4%D0%B5%D0%BC%D0%B8%D1%8F Should be: ?q=C%23+.NET+4.0 Should be: ?q=%D0%B1%D0%B8%D1%80%D0%B0

The HTTP Protocol How HTTP Works?

HTTP  HTTP (Hyper Text Transfer Protocol)  Client-server protocol for transferring Web resources (HTML files, images, styles, etc.)  Important properties of HTTP  Request-response model  Text-based format  Relies on unique resource URLs  Provides resource metadata (e.g. encoding)  Stateless (cookies and web storages can overcome this) 12

HTTP: Request-Response Protocol  Client program  Running on end host  Requests a resource HTTP Request HTTP Response 13  Server program  Running at the server  Provides resources A Single HTTP Transaction Web Client Web Server

14  HTTP Request  HTTP Response HTTP Transaction: Example HTTP/ OK Date: Mon, 5 Jul :09:03 GMT Server: Microsoft-HTTPAPI/2.0 Last-Modified: Mon, 12 Jul :33:23 GMT Content-Length: 54 <CRLF><html><title>Hello</title> Welcome to our site Welcome to our site The empty line denotes the end of the response header GET /courses/javascript HTTP/1.1 Host: User-Agent: Mozilla/5.0 <CRLF> The empty line denotes the end of the request header

15  HTTP defines methods to indicate the desired action to be performed on the identified resource HTTP Request Methods MethodDescription GETRetrieve a resource PUTUpdate a resource POSTStore a resource DELETERemove a resource HEADRetrieve the resource's headers

HTTP Request Message

17  Request message sent by a client consists of:  Request line  Request method (GET, POST, PUT, DELETE, …)  Resource URI  Protocol version  Request headers – additional parameters  Body – optional data HTTP Request Message HTTP/ HTTP/ <headers> <body>

18  Example of HTTP GET request: HTTP GET Request – Example GET /courses/javascript HTTP/1.1 Host: Accept: */* Accept-Language: bg Accept-Encoding: gzip, deflate User-Agent: Mozilla/4.0(compatible;MSIE 6.0; Windows NT 5.0) Connection: Keep-Alive Cache-Control: no-cache <CRLF> HTTP request line HTTP headers The request body is empty

19  Example of HTTP POST request: HTTP POST Request – Example POST /webmail/login.phtml HTTP/1.1 Host: Accept: */* Accept-Language: bg Accept-Encoding: gzip, deflate User-Agent: Mozilla/4.0(compatible;MSIE 6.0; Windows NT 5.0) Connection: Keep-Alive Cache-Control: no-cache Content-Length: 59 <CRLF>LOGIN_USER=menteDOMAIN_NAME=abv.bgLOGIN_PASS=top*secret!<CRLF> HTTP request line HTTP headers The request body contains the submitted data

20  Example of HTTP conditional GET request:  Fetches the resource only if it has been changed at the server  Server replies with " 304 Not Modified " if the resource has not been changed  Or " 200 OK" with the latest version otherwise Conditional HTTP GET – Example GET /apply HTTP/1.1 Host: User-Agent: Gecko/ Firefox/3.6 If-Modified-Since: Tue, 9 Mar :12:23 GMT <CRLF>

HTTP Response Message

22  Response message sent by the server consists of:  Status line  Protocol version  Status code  Status phrase  Response headers  Provide meta data  Body  The content of the response HTTP Response Message HTTP/ HTTP/

23  Example of HTTP response from the Web server: HTTP Response – Example HTTP/ OK Date: Fri, 17 Jul :09:18 GMT+2 Server: Apache/ (Linux) Accept-Ranges: bytes Content-Length: 84 Content-Type: text/html <CRLF><html> Test Test Test HTML page. Test HTML page. </html> HTTP response status line HTTP response headers The HTTP response body

24  Example of HTTP response with error result: HTTP Response – Example HTTP/ Not Found Date: Fri, 17 Nov :09:18 GMT+2 Server: Apache/ (Linux) Connection: close Content-Type: text/html <CRLF><HTML><HEAD> 404 Not Found 404 Not Found </HEAD><BODY> Not Found Not Found The requested URL /img/logo.gif was not found on this server. The requested URL /img/logo.gif was not found on this server. Apache/ Server at Port 80 Apache/ Server at Port 80 </BODY></HTML> HTTP response status line HTTP response headers The HTTP response body

25  HTTP response code classes  1xx : informational (e.g., " 100 Continue ")  2xx : successful (e.g., " 200 OK ")  3xx : redirection (e.g., " 304 Not Modified ", " 302 Found ")  4xx : client error (e.g., " 404 Not Found ")  5xx : server error (e.g., " 503 Service Unavailable ")  " 302 Found " redirects the Web browser to another URL HTTP Response Codes

26  HTTP GET requesting a moved URL:  The HTTP response says the browser should request another URL: Browser Redirection GET / HTTP/1.1 Host: User-Agent: Gecko/ Firefox/3.6 <CRLF> HTTP/ Moved Permanently Location: …

27  The Content-Type header at the server specifies how the output should be processed  Examples: Content-Type and Disposition Content-Type: text/html; charset=utf-8 Content-Type: application/pdf Content-Disposition: attachment; filename="Report-April-2010.pdf" UTF-8 encoded HTML page. Will be shown in the browser. This will download a PDF file named Financial-Report-April-2010.pdf

28 Type/SubtypeDescription application/jsonJSON data image/pngPNG image image/gifGIF image text/htmlHTML text/plainText text/xmlXML video/mp4MP4 video Common MIME Types

HTML, XML, JSON, RSS Comparing the Common Web Data Formats

30  Hyper Text Markup Language ( HTML )  Notation for describing formatted text with images and hyperlinks  Interpreted and displayed by the Web browsers  A Web ( HTML ) page consists of:  HTML file  CSS stylesheet file (optional)  Images (optional)  Other resources (optional)  HTML is straight-forward and easy to learn HTML <html> HTML Example HTML Example Welcome to my blog Welcome to my blog This is my first paragraph This is my first paragraph This is my second paragraph This is my second paragraph This is a div This is a div </html>

31  XML (Extensible Markup Language) is markup-language for encoding documents in machine-readable form  Text-based format  Consists of tags, attributes and content  Provide data and meta-data in the same time XML <library> HTML 5 Bay Ivan HTML 5 Bay Ivan WPF 4 Microsoft WPF 4 Microsoft WCF 4 Kaka Mara WCF 4 Kaka Mara UML 2.0 Bay Ali UML 2.0 Bay Ali </library>

32  RSS (Really Simple Syndication)  Family of Web feed formats for publishing frequently updated works  E.g. blog entries, news headlines, videos, etc.  Based on XML, with standardized XSD schema  RSS documents (feeds) are list of items  Each containing title, author, publish date, summarized text, and metadata  Atom protocol aimed to enhance / replace RSS RSS

33 RSS – Example <channel> W3Schools Home Page W3Schools Home Page Free web building tutorials Free web building tutorials RSS Tutorial RSS Tutorial New RSS tutorial on W3Schools New RSS tutorial on W3Schools XML Tutorial XML Tutorial New XML tutorial on W3Schools New XML tutorial on W3Schools </channel></rss>

34  JSON (JavaScript Object Notation)  Standard for representing data structures and associative arrays  Lightweight text-based open standard  Derived from the JavaScript language JSON { "firstName": "John", "lastName": "Smith", "age": 25, "firstName": "John", "lastName": "Smith", "age": 25, "address": { "streetAddress": "Vasil Kynchev 26", "address": { "streetAddress": "Vasil Kynchev 26", "city": "Sofia", "postalCode": "2400" }, "city": "Sofia", "postalCode": "2400" }, "phoneNumber": [{ "type": "home", "number": " "}, "phoneNumber": [{ "type": "home", "number": " "}, { "type": "fax", "number": " " }] { "type": "fax", "number": " " }]}, { "firstName": "Bay", "lastName": "Ivan", "age": 79 }

Web Services Web Services and SOA Architecture

 A web service is a method of communication between two devices in WWW  The server device exposes services  The client consumes these services  Web services are a main part of the SOA architecture  Database and business logic on the server (backend)  The server exposes public services  UI logic on the client  Consumes these services Web Services 36

RESTful Web Services Lightweight Architecture for Web Services

 Application state and functionality are resources  Resources are used as common data files  Every resource has an URI  All resources share a uniform interface  This natively maps to the HTTP protocol What is REST? "Representational state transfer (REST) is a style of software architecture for distributed hypermedia systems such as the World Wide Web." REST 38

39  One URI for a resource, multiple operations  Add a new document "RestTalk" in category "Code"  PUT  Get the document / some page  GET  GET  Remove the document  DELETE  Retrieve metadata  HEAD RESTful Services

AJAX Asynchronous JavaScript and XML

41  AJAX is acronym of Asynchronous JavaScript and XML  Technique for background loading of dynamic content and data from the server side  Allows dynamic client-side changes  Two types of AJAX  Partial page rendering – loading of HTML fragment and showing it in a ( AHAH )  JSON service – loading JSON object and client-side processing it with JavaScript / jQuery AJAX

42 AJAX Diagram Web Client Web Server 1. HTTP Request 2. HTTP Response (HTML Page) AJAX Request AJAX handler AJAX Response + call handler UI Interaction DOM Manupulation Returns data as JSON, HTML

43  Technically, AJAX is a group of technologies working together  HTML & CSS for presentation  The DOM for data display & interaction  XML (or JSON) for data interchange  XMLHttpRequest for async communication  JavaScript to use the above AJAX

44  AJAX uses HTTP  Requests have headers – GET, POST, HEAD, etc.  Requests have bodies – XML, JSON or plain text  The request must target a resource with a URI  The resource must understand the request  Server-side logic  Requests get a HTTP Response  Header with a body AJAX (2)

The Same Origin Policy i.e. Don't Talk to Strangers

46  Same Origin Policy is  Security restriction for browser-side programming languages  Scripts running on a page  Can access all pages from the same site (same origin)  Cannot access pages on different sites (different origin)  This also applies to XMLHttpRequest (AJAX calls)  Sent only between pages within the same origin Same Origin Policy

47  Origin is defined using:  Application layer protocol (e.g. http )  Domain name (e.g. example.com )  Port number (e.g. example.com:8080 )  Two resources are of the same origin if all of the above match Origin Determination Rules

48  The "Same Origin Policy" is sometimes too restrictive  Large sites with lots of subdomains  Accessing web services  Ways of "relaxing"  Cross-Origin Resource Sharing (CORS)  A site explicitly allows "HTTP calls from everywhere"  document.domain  Can be set to a super domain when in proper subdomain  Cross document messaging  Allowing documents to communicate across different origins  Workaround: JSONP (uses to skip the same origin policy) Relaxing the Same Origin Policy

49  CORS allows a site to declare its cross-domain origin policy CORS  "Accessible from everywhere" / "accessible from certain origins"  CORS: how it works?  The browser sends one-time HTTP OPTIONS request to ask the server for cross-domain access permissions  The server accepts / denies the request Cross-Origin Resource Sharing (CORS) HTTP/ OK Access-Control-Allow-Origin: * … OPTIONS /some-service/ HTTP/1.1 Host: server-site.com Origin:

Web Developer Tools Simulating and Tracking Web Traffic

51  Fiddler – HTTP proxy  Intercepts the HTTP traffic  Analyzes the HTTP conversation  Free tool (by Telerik) –  Firebug plug-in for Firefox  A must have for Web developers  The ultimate tool for monitoring, editing and debugging HTTP, HTML, CSS, JavaScript, etc.  Free, open-source – Web Developer Tools

52  Web Developer Tools  Built-in in Google Chrome and Opera  Network requests logging  Code execution timeline  Postman  Google app  Perform HTTP requests  Get from Chrome Web StoreChrome Web Store Web Developer Tools (2)

53  What is the difference between WWW & Internet ?  What is query string?  What is HTTP? How is done the communication?  What does HTTP request and response contain?  What is RSS used for? What is the format of XML?  What is REST?  What does AJAX give us?  What is the Same Origin Policy?  What is CORS? Summary

? ? ? ? ? ? ? ? ? HTTP, AJAX and REST

License  This course (slides, examples, demos, videos, homework, etc.) is licensed under the "Creative Commons Attribution- NonCommercial-ShareAlike 4.0 International" licenseCreative Commons Attribution- NonCommercial-ShareAlike 4.0 International 55  Attribution: this work may contain portions from  "JavaScript Applications" course by Telerik Academy under CC-BY-NC-SA licenseJavaScript ApplicationsCC-BY-NC-SA

Free Software University  Software University Foundation – softuni.orgsoftuni.org  Software University – High-Quality Education, Profession and Job for Software Developers  softuni.bg softuni.bg  Software Facebook  facebook.com/SoftwareUniversity facebook.com/SoftwareUniversity  Software YouTube  youtube.com/SoftwareUniversity youtube.com/SoftwareUniversity  Software University Forums – forum.softuni.bgforum.softuni.bg