Type Safely

Type Safely

Share this post

Type Safely
Type Safely
Construct a URL safely using enums instead of raw strings

Construct a URL safely using enums instead of raw strings

Daily Coding Tip 002

Type Safely's avatar
Type Safely
Dec 20, 2020
∙ Paid

Share this post

Type Safely
Type Safely
Construct a URL safely using enums instead of raw strings
Share

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
© 2025 Type Safely
Privacy ∙ Terms ∙ Collection notice
Start writingGet the app
Substack is the home for great culture

Share