Type Safely

Share this post
Construct a URL safely using enums instead of raw strings
typesafely.substack.com

Construct a URL safely using enums instead of raw strings

Daily Coding Tip 002

Type Safely
Dec 20, 2020
Share this post
Construct a URL safely using enums instead of raw strings
typesafely.substack.com

Here’s how to safely create URLs with the lowest reliance on raw strings possible.

It may seem like a lot but we’re basically combining enums with a raw type of String with URLComponents. This structure provides a way to individually add the scheme, host, and path components, instead of passing a raw string that could fail.

Instead of relying on a hard-co…

Keep reading with a 7-day free trial

Subscribe to Type Safely to keep reading this post and get 7 days of free access to the full post archives.

Already a paid subscriber? Sign in
© 2022 Type Safely
Privacy ∙ Terms ∙ Collection notice
Publish on Substack Get the app
Substack is the home for great writing