1

im trying to convert the call to the FORVO api (forvo.com) from a hardcoded url string to assigning the request parameters one by one to a ForvoRequestClass's properties that i created in C# via .AddParameter method...but when the request is made...it turns it into querystring format like this:

http://apifree.forvo.com/?key=[mykeygoeshere]&language=en&format=json&limit=1&order=rate-desc&sex=f&type=word&word=APPLE}

instead of like this:

http://apifree.forvo.com/key/[mykeygoeshere]/language/en/format=json/limit/1/order/rate-desc/sex/f/type/word/word/APPLE

i have tried various ways to call it using RestSharp...to no avail...any ideas...??

pratim_b
1,22014 silver badges31 bronze badges
asked Mar 24, 2014 at 13:51

1 Answer 1

1

Ok...i believe i found the answer. On the github repo for RestSharp ( [1]: https://github.com/restsharp/RestSharp/wiki/ParameterTypes-for-RestRequest) I found the following helpful section:

UrlSegment

Unlike GetOrPost, this ParameterType replaces placeholder values in the RequestUrl:

var rq = new RestRequest("health/{entity}/status");
rq.AddParameter("entity", "s2", ParameterType.UrlSegment);

When the request executes, RestSharp will try to match any {placeholder} with a parameter of that name (without the {}) and replace it with the value.

So the above code results in "health/s2/status" being the Url.

So with this info, I constructed my url string with placeholders for each of the parameters for Forvo like this:

/key/{key}/format/{format}/action/{action}/language/{language}/sex/{sex}/order/{order}/limit/{limit}/type/{type}/word/{word}

My final code to then do the substitution was this:

IRestClient client = new RestClient(soundRequest.SiteUrlValue);
 request.AddParameter(soundRequest.ApiKeyName, soundRequest.ApiKeyValue, ParameterType.UrlSegment);
 request.AddParameter(soundRequest.ActionName, soundRequest.ActionValue, ParameterType.UrlSegment);
 request.AddParameter(soundRequest.LanguageName, soundRequest.LanguageValue, ParameterType.UrlSegment);
 request.AddParameter(soundRequest.FormatName, soundRequest.FormatValue, ParameterType.UrlSegment);
 request.AddParameter(soundRequest.SexName, soundRequest.SexValue, ParameterType.UrlSegment);
 request.AddParameter(soundRequest.OrderName, soundRequest.OrderValue, ParameterType.UrlSegment);
 request.AddParameter(soundRequest.LimitName, soundRequest.LimitValue, ParameterType.UrlSegment);
 request.AddParameter(soundRequest.TypeName, soundRequest.TypeValue, ParameterType.UrlSegment);
 request.AddParameter(soundRequest.WordName, soundRequest.WordValue, ParameterType.UrlSegment);
answered Mar 25, 2014 at 11:22

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.