You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Notice the slash after "endpoint", without that slash "/" the API call would fail or improperly redirect (301)
And for now as you suggested, I made an extension method, so it wouldn't break the fluent syntax.
It's different than what you suggested but this gives more control, since this is a special case, most APIs don't have this slash at the end.
namespace Flurl.Extensions
{/// <summary>/// A set of string extension methods for working with Flurl URLs/// </summary>publicstaticclassStringExtensions{/// <summary>/// Explicitly adds a '/' character to the end of the Url./// </summary>/// <param name="url"></param>/// <returns></returns>publicstatic Url AppendPathSeparator(thisstringurl){if(!string.IsNullOrEmpty(url)&&!url.EndsWith("/"))url+="/";returnnew Url(url);}/// <summary>/// Explicitly adds a '/' character to the end of the Url./// </summary>/// <param name="url"></param>/// <returns></returns>publicstatic Url AppendPathSeparator(thisUrlurl){if(url!=null&&!string.IsNullOrEmpty(url.Path)&&!url.Path.EndsWith("/"))url+="/";returnnew Url(url);}}}
I'm of the opinion (and I hope this works for you) that the best solution is for Flurl to simply not trim the trailing slash when it's explicitly provided. So you can call url.AppendPathSegment("endpoint/") and it'll be left alone.
AppendPathSegment trims the trailing slash when calling API's like this:
Notice the slash after "endpoint", without that slash "/" the API call would fail or improperly redirect (301)
And for now as you suggested, I made an extension method, so it wouldn't break the fluent syntax.
It's different than what you suggested but this gives more control, since this is a special case, most APIs don't have this slash at the end.
I use it like this:
The text was updated successfully, but these errors were encountered: