SOAP and REST At Odds (2017)
thehistoryoftheweb.com
thehistoryoftheweb.com
Anyway now I use JSON over HTTP and I don’t care if it’s REST or not.
REST is trendy because everyone sells imaginary features like self-discovery, performance and universal clients, while actually shipping random ad-hoc JSON snippets over "pretty" URLs.
REST is cool because it doesn't actually exist, so there's nothing specific to criticize about it that sticks. Any attempt at REST critique is quickly drown out by the noise of thousands of REST fans saying "but this is not REST".
Recently I ran into an issue where the SOAP client library I was using escaped values like you normally would in XML: <xml>1 < 2 & cetera</xml> ... but the SOAP server required CDATA syntax, like this: <xml><![CDATA[1 < 2 & cetera]]></xml>, so the schema didn't help much there either.
The reason JSON got past this stage is that the JSON spec is sufficiently simple that when a popular JSON parser for every platform/language got established, people just used it.
XML on the other hand is a nightmare of complexity and it even had the occasional remote code execution vulnerabilities in some parsers (they're that complex). Which means many applications would "handroll" something that amounts to a child's interpretation of what XML is and expect that. Truly unfortunate.
I wonder if SOAP based on JSON would be more successful. Probably yes. But we didn't have it back then.
KISS
Lots of people argue over whether or not their API is RESTful.
Use of HTTP verbs is only one method of metadata intent of an operation ; but it often gets watered down to this.
Every single REST API in the world has been a part of at least one "is this RESTful" argument.
Exactly zero (zilch, nada) SOAP APIs in the world have been a part of a "is this SOAPful" argument.
Similarly there's no such arguments when using GraphQL or gRPC.
Therefore all conversations about "REST vs. GraphQL/SOAP/gRPC" make no sense, it's like comparing apples and recipe books.
But horror story aside, consuming a decent SOAP endpoint with a good client library can be practically magical.
Between attrs (https://www.attrs.org/), cattrs (https://cattrs.readthedocs.io/), and the aforementioned zeep soap client I've got a serialisation pipeline from soap endpoint into an attrs dataclass with type hints and basic type validation down to a snippet so small it fits right here (type hints removed to minimise size).
from zeep import helpers
from cattr import structure
def zeep_to_attrs(zeep_object, attrs_class):
"""Serialize zeep objects to native python data structures"""
return structure(helpers.serialize_object(zeep_object, target_cls=dict), attrs_class)Probably the slow realization most of REST's promises were just vapor, and all we need is ad-hoc JSON HTTP APIs.
there is no new thing under the sun
Rince and repeat, while selling a couple of books and conference tickets I guess.