i have a protocol that abstracts over types that can be created from an (partial) HTTP requests. it has requirements like:
import NIOCore
import NIOHTTP1
public
protocol ExpressibleByHTTPRequest
{
init?(promise:EventLoopPromise<Server.Resource>,
source:SocketAddress?,
head:HTTPRequestHead)
init?(promise:EventLoopPromise<Server.Resource>,
source:SocketAddress?,
head:HTTPRequestHead,
body:[ByteBuffer],
end:HTTPHeaders?)
}
but i don’t feel like ExpressibleByHTTPRequest is a good name for this protocol, because an HTTP request isn’t an expression, like an integer literal or a string literal.
there’s another precedent we could use: HTTPRequestConvertible, but that doesn’t really make sense, because this protocol doesn’t require the type to be able to encode itself back into an HTTP request - the transformation is unidirectional. ConvertibleFromHTTPRequest is a bit better, but i don’t like invoking the idea of “conversion”; the transformation is expected to discard most of the information from the original request.
what to call this protocol?
3 Likes
ConstructibleFrom_? BuildableFrom_? ObtainableFrom_?
2 Likes
jeremyp
(Jeremy Pereira)
3
DecodableFromHTTPRequest?
I think DerivableFrom_ reads fairly well as a native English speaker. Not super different than what @ExFalsoQuodlibet has suggested though tbh.
Definition of derive (according to Webster's):
to take, receive, or obtain especially from a specified source
Sounds a lot like you are "obtaining" these objects from the HTTP Requests, doesn't it?
2 Likes
rayx
(Huan Xiong)
5
I'm not a native English speaker, but I wonder if it's better to use a passive verb than "able" in this case? In my understanding, the use of "able" in Swift naming convention usuallly means an alternative way to initialize a value. In this case, however, it seems those types can only be built from http request. So, how about BuiltFrom_ or DerivedFrom_?
1 Like
What about SourcedFromHTTPRequest? I'm thinking here of the terminology used in constructors such as Set which are created from other types, e.g. Set's init<Source>(Source). This does not seem to be universal across the Standard Library, though, e.g. String has init<S>(S), but then what does the "S" stand for?
Torust
(Thomas Roughton)
7
HTTPRequestConstructable (/Constructible)?
HTTPRequestRepresentable could be another option. Or HTTPRequestDisguisable if you’re feeling whimsical 