Stories
Slash Boxes
Comments

SoylentNews is people

posted by janrinok on Thursday December 08 2022, @11:07AM   Printer-friendly
from the hello-world-of-networking dept.

Software engineer, Dave DeLong, has written an 18-part series on building an HTTP framework in Swift. Apple's Swift programming language is a general-purpose, open source, compiled programming language intended to replace Objective-C. It is licensed 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 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
(2017) Undefined Behavior != Unsafe Programming
(2016) New Swift Release Has Port to Ubuntu
(2015) Apple's Swift Language Might Actually be Good
(2014) Apple Aims to Speed up Coding with its own Swift Programming Language


Original Submission

 
This discussion was created by janrinok (52) for logged-in users only, but now has been archived. No new comments can be posted.
Display Options Threshold/Breakthrough Mark All as Read Mark All as Unread
The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
  • (Score: 1, Informative) by Anonymous Coward on Thursday December 08 2022, @06:16PM

    by Anonymous Coward on Thursday December 08 2022, @06:16PM (#1281752)

    I recently wrote a web service in Go (first time I had touched web programming in 20 years). It was ridiculously easy, and ridiculously fast. Threading was trivial. Thanks to it being a "real" compiled language, by the time it compiled cleanly it worked perfectly.

    Starting Score:    0  points
    Moderation   +1  
       Informative=1, Total=1
    Extra 'Informative' Modifier   0  

    Total Score:   1