Stories
Slash Boxes
Comments

SoylentNews is people

SoylentNews is powered by your submissions, so send in your scoop. Only 18 submissions in the queue.

Submission Preview

Link to Story

An 18-part Series on Building a Swift HTTP Framework

Accepted submission by canopic jug at 2022-12-04 11:18:51 from the the-hello-world-of-networking dept.
Software

Software engineer, Dave DeLong, has written an 18-part series on building an HTTP framework in Swift [davedelong.com]. Apple's Swift [apple.com] programming language is a general-purpose, open source, compiled programming language intended to replace Objective-C. It is licensed [swift.org] under the Apache 2.0 license. In his series, Dave covers an Intro to HTTP, Basic Structures, Request Bodies, Loading Requests, Testing and Mocking, Chaining Loaders, Dynamically Modifying Requests, Request Options, Resetting, Cancellation, Throttling, Retrying, Basic Authentication, OAuth Setup, OAuth, and Composite Loaders.

Over the course of this series, we’ve started with a simple idea and taken it to some pretty fascinating places. The idea we started with is that a network layer can be abstracted out to the idea of “I send this request, and eventually I get a response”.

I started working on this approach after reading Rob Napier’s blog post on protocols [robnapier.net] on protocols. In it, he makes the point that we seem to misunderstand the seminal “Protocol Oriented Programming” idea introduced by Dave Abrahams Crusty at WWDC 2015. We especially miss the point when it comes to networking, and Rob’s subsequent posts go in to this idea further.

One of the things I hope you’ve realized throughout this blog post series is that nowhere in this series did I ever talk about Codable. Nothing in this series is generic (with the minor exception of making it easy to specify a request body). There is no mention of deserialization or JSON or decoding responses or anything. This is extremely deliberate.

The point of HTTP is simple: You send an HTTP request (which we saw has a very well-defined structure) and you get back an HTTP response (which has a similarly well-defined structure). There’s no opportunity to introduce generics, because we’re not dealing with a general algorithm.

So this begs the question [sic]: where do generics come in? How do I use my awesome Codable type with this framework? The answer is: the next layer of abstraction.

HTTP, or at least through version HTTP 1.1, is a straight forward, text-based, human-readable specification.

Previously:
(2019) Apple Patents Programming Language Feature [soylentnews.org]
(2017) Undefined Behavior != Unsafe Programming [soylentnews.org]
(2016) New Swift Release Has Port to Ubuntu [soylentnews.org]
(2015) Apple's Swift Language Might Actually be Good [soylentnews.org]
(2014) Apple Aims to Speed up Coding with its own Swift Programming Language [soylentnews.org]


Original Submission