Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to make this Web Api to work?
Message
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Versions des environnements
Environment:
C# 5.0
OS:
Windows 10
Database:
MS SQL Server
Divers
Thread ID:
01658678
Message ID:
01658774
Vues:
65
This message has been marked as a message which has helped to the initial question of the thread.
Depending on how you send the data on the client:

* Using jQuery or any other wrapper library it'll automatically encode form variables and URL parameters
* Even if you hardcode the query string parameters on the URL the browser will automatically encode them

Using a dictionary in this situation just makes the API a bit convoluted because it's not clear what the API expects for parameters exactly. If you're using GET, you can just map query string parameters directly to parameter names (ie. &id=xxxx) maps to Get(string id) or [Route(person/{id}] and person/xxxx. You don't even need [FromUri]. Your approach works but it's much less expressive for the person consuming the API.

+++ Rick ---

>>Why are you passing data (a dictionary) on the URL via [HttpGet]? SHouldn't that go into an [HttpPost] and then [FromBody]? This seems bad behavior for a REST service.
>>
>
>I have auto-complete textbox on the page. For this to function I need to pass the id (int) and a string. I can pass them as parameters, but I would need to hash the string then before sending to API. I was thinking that sending a simple object (KeyValuePair) would be better than sending two parameters.
>
>I can also use a post instead of the get, but I was thinking since the purpose is to receive information and not really post anything back, get would be a better choice.
+++ Rick ---

West Wind Technologies
Maui, Hawaii

west-wind.com/
West Wind Message Board
Rick's Web Log
Markdown Monster
---
Making waves on the Web

Where do you want to surf today?
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform