-
Notifications
You must be signed in to change notification settings - Fork 42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enforcing trailing slash required by API #75
Comments
Sure I've had to work with an API like that before. You can use a Delegating Handler to add the trailing slash: var config = new Config()
.UseHandler((request, token, next) =>
{
request.RequestUri = new Uri(request.RequestUri.ToString() + "/");
return next(request, token);
});
dynamic client = new RestClient("https://jsonplaceholder.typicode.com", config);
// With the Delegating Handler above this would call https://jsonplaceholder.typicode.com/my-users/
var user = await client
.Resource("my-users")
.Get(); Let me know if this works for you. D |
Hello, D! |
Found this in HttpVerbCommand.cs. Looks like I need a custom build without those lines for now:)
|
Yes that's the place to do it, I tested it and it works as expected. Unfortunately it will need to be a custom build for now. I have a story in the backlog for allowing chain extension with your own dynamic commands. Then it would be as simple as writing your command and doing Sorry it wasn't as easy as it should of been to do this. |
I also have thought of a easy change I can add that might workaround this issue, I try and get something out today. |
Perhaps an optional parameter would fit a call like .Resource(string, SlashTrimmingOption.NoTrimming)? enum SlashTrimmingOption {
} At least from the .Resource(...) usage perspective it looks an appropriate place to put. If we used chaining to build the Uri, then we need some other solution Like an explicit .Slash() call. |
What I was thinking is if you passed a slash in Resource() not to trim it, unlikely to be a breaking change and keeps it clean. I'll definitely add this just half though 3.3.3 ate the moment. I leave this open and close when I release 3.3.3 with this fix. |
Hi!
I'm a new user of your library and it looks very convenient and promising in most cases. However, I am consuming an API that has resources containing dashes and requiring trailing slashes in the endpoint URLs in some cases. I haven't deeply debugged RestClient yet but it seems that the slash I provide in Resource("endpoint/") is omitted. How can I customize RestClient to use URLs I provide verbatim without any trimming?
Thank you in advance.
The text was updated successfully, but these errors were encountered: