ploeh / Hyprlinkr

A URI building helper library for ASP.NET Web API
MIT License
197 stars 34 forks source link

Implemented ParseUri #2

Closed dhilgarth closed 12 years ago

dhilgarth commented 12 years ago

Please see discussion on Issue 1: https://github.com/ploeh/Hyprlinkr/issues/1 I implemented three methods:

  1. ParseUri: Calls TryParseUri
  2. TryParseUri: Parses an Uri into an HttpActionContext. This includes all the information about which action gets called on which controller as well as the parameters for the action method 3: Verify: Verifies that an HttpActionContext indeed points to the action specified by an expression.

Some notes about Postel's law:

  1. Over-parametrization in the URI is not a problem
  2. Order of query parameters is irrelevant in the URI
  3. Optional parameters can be missing in the URI
  4. Permanent redirect routes are followed. This means that old links are verified successfully, if the rest of the application also supports those old links. A RedirectRouteHandler can be used to achieve this. See Ploeh.Hyprlinkr.UnitTest.RedirectRouteHandler for an implementation.

Some more notes:

  1. I am not really happy with the names of the interfaces and the class. Suggestions for better names are welcome.
  2. I am not really happy with the fact that ParseUri throws a generic ArgumentException if an error occurrs. I am also not happy with the way ResourceLinkVerifier.GetActionDescriptor is implemented. Maybe it would be a better idea to switch the implementation around? Make TryParseUri call ParseUri, put that call in a try-catch block and return false if an exception is caught. Still smells... Suggestions are welcome.
ploeh commented 12 years ago

Thank you. The code is now live as Hyprlinkr 0.4.0 :)

dhilgarth commented 12 years ago

Nice, thank you!