I am writing an .NET wrapper API for the Netflix API.
At this point I can choose to represent URLs as either strings or URI objects. Seems to me there is a good case for both.
So if you were using an API, which would you prefer?
I am writing an .NET wrapper API for the Netflix API.
At this point I can choose to represent URLs as either strings or URI objects. Seems to me there is a good case for both.
So if you were using an API, which would you prefer?
The below quote is from: Framework Design Guildelines
I highly recommend this book to anyone developing frameworks on .Net
EDIT (per comments): The book specifically states: "Extensive manipulation of URI-related data using plain strings has been shown to cause many security and correctness problems." I am not sure what additional justification you want for using System.Uri / UriBuilder. Additionally, why wouldn't you want to take advantage of the framework to read/manipulate a URI?
When designing an API that will be used by others it is important to make them approachable, as well as reliable. For this reason the book does mention, you should provide "nice" overloads for common functionality. However, to ensure correctness, you should always implement the underlying code with URIs.
Can you please clarify your wants, or reasons to use only strings?
I would say that you should represent it as URI. However, if I am a user of your API and I am having to continuously convert string based URLs to URI to use your API, then I would be a pissed off user.
What I am saying is that you need to assess what kind of audience will be consuming your API.
One thing I found was that while writing
string
-accepting methods, I'd always have to initialize aUri
object anyway just to validate the string, such that theUriFormatException
would then propagate out of the method if the user passed a bad string. But if you acceptUri
s only, as I did after getting yelled at (rightfully) by FxCop, then you always know your input is valid---which to me seems like a very good sign that you're designing your API correctly.