Sunday, August 24, 2014

Type-safe URL Routes in Swift

Chris Eidhof:

I think it’s a really nice way of building APIs. The Github enum makes it very clear which endpoints are available, and the form of their parameters. By defining these things once, we can make it much harder for users of this API to make mistakes. For example, it’s not possible to pass in a nil username, because the UserProfile takes a non-optional string. If we wanted to add optional parameters, we have to be explicit about that.

The other nice thing is that all of the above code is independent of any networking library.

Comments

Stay up-to-date by subscribing to the Comments RSS Feed for this post.

Leave a Comment