1

I am using NancyFX to host our REST APIs for Web site. We have user table in database, which I would like to update for:

1) Full user update - updates all fields 2) Partial user update - updates only single field

We are using Nancy 0.7 - so currently it does not have PATCH support - I can only use PUT

I have defined my API like

PUT ["/user/{username}"] - for complete update using passed-in user object value
PUT ["/user/{username}/id/{newid}"] - for updating user id only

However, when I call the second API (to update id only) - it never gets trapped by Nancy - and Nancy always call the method to fully update user i.e. PUT ["/user/{username}"]

No matter, what order I declare the APIs, Nancy always call the full user update endpoint only.

Need help, so that I can use both APIs using PUT from our client applications properly.

Tejas Vora
  • 538
  • 9
  • 19

2 Answers2

1

In general, it is a good idea to UrlEncode any dynamic data components of your URI.

So, in your case:

PUT - /user/xyz@yahoo.com/id/123

would become

PUT - /user/xyz%40yahoo.com/id/123 

Nancy will take care of decoding the value for you, so when you extract it from your parameters dynamic object it will be back to xyz@yahoo.com

biofractal
  • 18,963
  • 12
  • 70
  • 116
  • it is fine for '@' character - but Nancy has problems in decoding '+' characters - even if I use URL encode - Nancy decodes it as 'space' – Tejas Vora Oct 01 '12 at 15:57
  • Ah, this is not Nancy's fault, the plus (+) char is the urlencode char for space, if the data is sent from a form, otherwise it is the more usual %20. So if your data has a plus then Nancy will correctly decode this to a space. Try double encoding your data and single decode inside the Nancy handler or encode using javascript's `encodeURIcomponent()`. See [URL encoding the space character: + or %20?](http://stackoverflow.com/a/1634314/776476) for more info. – biofractal Oct 01 '12 at 18:31
0

Found the problem - It is to do with '@' character in user name - special character.

if username contains '@' character then Nancy never matches the route for PUT - /user/xyz@yahoo.com/id/123 to PUT ["/user/{username}/id/{newid}"]

it always matches route for PUT - /user/xyz@yahoo.com/id/123 to PUT ["/user/{username}"]

Tejas Vora
  • 538
  • 9
  • 19