Web Services Prerequisites
Jakub Klímek
Tools
Lectures and tutorials on XML and XML Schema in NPRG036 - Data Formats
Task 1 - ping
Use ping to determine the IP address for data.gov.cz using DNS
Task 1 - ping - solution
$ ping data.gov.cz
PING data.gov.cz (40.69.221.188) 32 bytes of data.
Alternatively, using nslookup
$ nslookup data.gov.cz
Server: UnKnown
Address: 2a03:a900:2000:5a6::1
Non-authoritative answer:
Name: data.gov.cz
Address: 185.17.214.226
Task 2 - telnet + HTTP
$ ping www.google.com
PING www.google.com (172.217.23.196) 56(84) bytes of data.
64 bytes from prg03s05-in-f196.1e100.net (172.217.23.196): icmp_seq=1 ttl=58 time=1.53 ms
Task 2 - PuTTY
If you are using PuTTY, use the “raw” connection:
Task 2 - telnet + HTTP - solution HTTP/1.0
$ telnet 172.217.23.196 80�Trying 172.217.23.196…�Connected to 172.217.23.196.�Escape character is '^]'.�GET / HTTP/1.0�
You should get HTML content here. If you look closely, it will be in the language of your region, e.g. Czech.
Task 2 - telnet + HTTP - solution HTTP/1.1
$ telnet 172.217.23.196 80�Trying 172.217.23.196…�Connected to 172.217.23.196.�Escape character is '^]'.�GET / HTTP/1.1�Host: www.google.com�
You should get HTML content here as well. In HTTP/1.1 you need to specify the Host: header, even though google is quite tolerant here.
Task 3 - telnet + HTTP + additional headers
Use telnet to get the spanish version of the google homepage.
Task 3 - telnet + HTTP + additional headers - solution
$ telnet 172.217.23.196 80
Trying 172.217.23.196...
Connected to 172.217.23.196.
Escape character is '^]'.
GET / HTTP/1.1
Host: www.google.com
Accept-Language: es
Task 4 - curl
Use curl to get the Google webpage
Use curl to get a spanish Google webpage
Task 4 - curl - solution
$ curl www.google.com
And if you want to see the communication:
$ curl -v www.google.com
Setting the header:
$ curl -v -H"Accept-Language: es" www.google.com
Task 5 - more content negotiation
Let’s have a resource identified by: https://data.gov.cz/zdroj/datové-sady/00006963/9b88bbed6f1effd48bd3e6b66232d8c9
Task 5 - more content negotiation - solution - telnet 1�(no longer working)
$ telnet 185.17.214.226 80�Trying 185.17.214.226…�Connected to 185.17.214.226.�Escape character is '^]'.�GET /zdroj/datové-sady/00006963/9b88bbed6f1effd48bd3e6b66232d8c9 HTTP/1.1�Host: data.gov.cz��HTTP/1.1 301 Moved Permanently�Server: nginx�Date: Sat, 06 Feb 2021 09:15:35 GMT�Content-Type: text/html�Content-Length: 162�Connection: keep-alive�Location: https://data.gov.cz/zdroj/datové-sady/00006963/9b88bbed6f1effd48bd3e6b66232d8c9
Task 5 - more content negotiation - solution - telnet 2
$ telnet 185.17.214.226 443�Trying 185.17.214.226…�Connected to 185.17.214.226.�Escape character is '^]'.�GET /zdroj/datové-sady/00006963/9b88bbed6f1effd48bd3e6b66232d8c9 HTTP/1.1�Host: data.gov.cz��HTTP/1.1 400 Bad Request�Server: nginx�Date: Sat, 06 Feb 2021 09:17:06 GMT�Content-Type: text/html; charset=utf-8�Content-Length: 248�Connection: close��<html>�<head><title>400 The plain HTTP request was sent to HTTPS port</title></head>�<body>�<center><h1>400 Bad Request</h1></center>�<center>The plain HTTP request was sent to HTTPS port</center>�<hr><center>nginx</center>�</body>�</html>�Connection closed by foreign host.
Task 5 - more content negotiation - solution - curl 1
$ curl -v https://data.gov.cz/zdroj/datové-sady/00006963/9b88bbed6f1effd48bd3e6b66232d8c9�$ curl -v -H"Accept: text/turtle" https://data.gov.cz/zdroj/datové-sady/00006963/9b88bbed6f1effd48bd3e6b66232d8c9�* Trying 185.17.214.226:443…�…�> GET /zdroj/datové-sady/00006963/9b88bbed6f1effd48bd3e6b66232d8c9 HTTP/2�> Host: data.gov.cz�> user-agent: curl/7.68.0�> accept: text/turtle�>�< HTTP/2 303�< server: nginx�< date: Sat, 06 Feb 2021 09:19:12 GMT�< content-type: text/html; charset=UTF-8�< content-length: 0�< location:�https://data.gov.cz/sparql?query=define%20sql%3Adescribe-mode%20%22CBD%22%20%20DESCRIBE%20%3Chttps%3A%2F%2Fdata.gov.cz%2Fzdroj%2Fdatové-sady%2F00006963%2F9b88bbed6f1effd48bd3e6b66232d8c9%3E&format=text%2Fturtle�< ...
Task 5 - more content negotiation - solution - curl 2
$ curl -v -H"Accept: text/turtle" https://data.gov.cz/sparql?query=define%20sql%3Adescribe-mode%20%22CBD%22%20%20DESCRIBE%20%3Chttps%3A%2F%2Fdata.gov.cz%2Fzdroj%2Fdatové-sady%2F00006963%2F9b88bbed6f1effd48bd3e6b66232d8c9%3E&format=text%2Fturtle�…�> GET /sparql?query=define%20sql%3Adescribe-mode%20%22CBD%22%20%20DESCRIBE%20%3Chttps%3A%2F%2Fdata.gov.cz%2Fzdroj%2Fdatové-sady%2F2F00006963%2F9b88bbed6f1effd48bd3e6b66232d8c9%3E HTTP/2�> Host: data.gov.cz�> user-agent: curl/7.68.0�> accept: text/turtle�>�< HTTP/2 200�< server: nginx�< date: Sat, 06 Feb 2021 09:22:08 GMT�< content-type: text/turtle; charset=UTF-8�< …�<�@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .�@prefix ns1: <https://data.gov.cz/slovn\u00EDk/nkod/typ-datov\u00E9-sady-dle-zdroje/> .�<https://data.gov.cz/zdroj/datov\u00E9-sady/2F00006963/9b88bbed6f1effd48bd3e6b66232d8c9> rdf:type ns1:DcatLkodSparql .�...
Task 5 - more content negotiation - solution - curl 3
curl can do the “follow redirect” for us using the -L parameter
$ curl -v -L -H"Accept: text/turtle" https://data.gov.cz/zdroj/datové-sady/00006963/9b88bbed6f1effd48bd3e6b66232d8c9
Task 5 - postman
Graphical UI
try with application/ld+json
Task 5 - postman
Problem: why is the turtle representation empty here?
Task 5 - postman
Postman allows you to export curl (and other) commands via the “code” button
Task 6 - observe HTTP communication in browser
Using your favorite web browser, GET a resource from the previous task and observe the HTTP communication
Hint:
Usually, there is a “Developer console” with a “Network” tab
Task 7 - XML
Create a simple XML document with
Check well-formedness
e.g. https://www.xmlvalidation.com/
or xmllint on linux
Task 7 - example
<?xml version="1.0" encoding="UTF-8"?>
<catalog xmlns="https://example.org/catalog" xmlns:ext="https://example.org/extensions">
<title xml:lang="en">My catalog</title>
<title xml:lang="cs">Můj katalog</title>
<description xml:lang="en">This is my dummy catalog</description>
<description xml:lang="cs">Toto je můj falešný katalog</description>
<contact-point kind="email">
<ext:name xml:lang="en">John Doe</ext:name>
<ext:e-mail>mailto:john@doe.org</ext:e-mail>
</contact-point>
<datasets>
<dataset>
<title xml:lang="en">Bikesharing in Brno</title>
<title xml:lang="cs">Sdílení kol v Brně</title>
<distributions>
<distribution media-type="application/xml">
<downloadURL>http://brno.cz/myfile.xml</downloadURL>
</distribution>
<distribution>
<accessService>
<endpointURL>https://brno.cz/myAPI</endpointURL>
<title xml:lang="en">My API</title>
</accessService>
</distribution>
</distributions>
</dataset>
<dataset>
<title xml:lang="en">Bikesharing in Prague</title>
<title xml:lang="cs">Sdílení kol v Praze</title>
<distributions>
<distribution media-type="text/csv">
<title xml:lang="en">CSV</title>
<downloadURL>http://praha.eu/myfile.csv</downloadURL>
</distribution>
</distributions>
</dataset>
</datasets>
</catalog>
24
Task 8 - XPath
Download: https://goo.gl/P36GBg
Use e.g. http://xpather.com/ or Altova XMLSpy (free trial & enterprise version in lab on Windows)
Task 9 - XML Schema
Homework
Homework scope
Needs to be more detailed than this.
Hospital
Reception
Investigation
Hospitalization
Surgery
Control
Economy
Utility
Homework scope: this seems sufficient