APIS
APIS
URLs
Every resource is uniquely Simple Operations
identified by a URL (PUT,GET,POST,DELETE)
© Ellis Horowitz Marco Papa 2006-2022 6
REST versus Other Approaches
• REST
– Software architectural style for distributed hypermedia systems like WWW
– Quickly gained popularity through its simplicity
• SOAP
– Protocol for exchanging XML-based message, normally using HTTP
– Much more robust way to make requests, but more robust than most APIs need
– More complicated to use
• https://www.w3schools.com/xml/xml_soap.asp
• XML-RPC
– RPC protocol with XML as an encoding and HTTP as a transport
– More complex than REST but much simpler than SOAP
– Supported by Python:
• https://docs.python.org/3/library/xmlrpc.html
• JSON-RPC
– RPC protocol encoded in JSON instead of XML
– Very simple protocol (and very similar to XML-RPC)
• https://www.jsonrpc.org/specification
HTTP/1.1 200 OK
Content-Type: text/html
...
<html>
<a href="1234">Moby Dick</a>
<a href="5678">XML QuickRef</a>
</html>
View book details
HTTP/1.1 200 OK
...
<html>
<a href="/orders/abcd">Order</a>
</html>
HTTP/1.1 200 OK
Content-type: text/xml
...
<?xml version="1.0"?>
<books xmlns="...">
<book href="http://.../1234/"/>
<book href="http://.../5678/"/>
</books> Web
Service
Get book details
HTTP/1.1 200 OK
Content-type: text/xml
...
<?xml version="1.0"?>
<book xmlns="...">
<title>Moby Dick</title>
...other book data...
<order href="http://.../orders/"/>
</book>
<shipping>...</shipping>
</order>
Web
Service
HTTP/1.1 201 Created
Location: http://.../abcd/
HTTP/1.1 200 OK
Content-type: text/json
{ "books": {
"book": [
{ "href": "http://.../1234/" },
{ "href": "http://.../5678/" }
]
}
}
JSON objects are returned
GET /books/1234/ HTTP/1.1
HTTP/1.1 200 OK
Content-type: text/json
{
"book": {
"title": "Moby Dick",
. . . other book data
"order": { "href": "http://.../orders" }
}
}
© Ellis Horowitz Marco Papa 2006-2022 12
REST & the JSON Web (2)
(order book)
XML/HTTP
stands for
REST
Data
ROADMAP