swift-aws-lambda-events icon indicating copy to clipboard operation
swift-aws-lambda-events copied to clipboard

Use Swift HTTP types package for status and method

Open jsonfry opened this issue 3 months ago • 2 comments

Use Swift HTTP types package for status and method

Motivation:

As mentioned in #46 there is some overlap between the definitions of http types in this library and in the recent Apple Swift HTTP Types library.

This means when working with Swift HTTP Types, you have to convert from the AWS Lambda Events representation of http types into Swift HTTP Types.

Modifications:

I have replaced the request method and response status Swift types in this library with those from Swift HTTP Types.

Result:

Now you must use Swift HTTP Types for request methods and response types.

Further discussion:

No Headers?

I initially indented to also replace the representation of headers to Swift HTTP Types' HTTPField, but this turned out to be... non-trivial. The way AWS encodes the different forms of headers in different situations and the way the Swift HTTP Types library handles encoding and decoding are both (of course) very different, so you can't just replace public let headers: [String: String] with public let header: HTTPFields.

I think I could have added manual encode and decode functions to the various types that have headers to support this, rather than relying on the synthized codable functions. But that seemed like overkill and a future maintenance burden that I am not in a place to decide about.

Extending Status and Method to add Codable support

In Swift HTTP Types, the higher level structs support Codable, but Method and Status themselves don't directly support Codable. Instead the structs that include Method and Status handle the encoding / decoding of those types. This means I've had to add a Codable implementation for Method and Status in this library. This seems a little odd to me. I wonder if that would be better placed in Swift HTTP Types?

jsonfry avatar Mar 25 '24 11:03 jsonfry