Flurl Client Usage with Placeholder in URL

41 Views Asked by At

We are aware that it's important to make sure Flurl clients are re-used where possible and that this is controlled via the URL that is supplied to the Get method of IFlurlClientFactory.

Some of the calls we are making will contain a placeholder value such as:

https://my.api.com/some/api/{0}

Clearly we don't want to call Get using the full URLs like https://my.api.com/some/api/1234 or https://my.api.com/some/api/5678 since we would be creating new clients for each.

However what is the effect of calling Get using https://my.api.com/some/api/{0} compared to removing the placeholder and using https://my.api.com/some/api/?

Do these equate to the same thing as we would be calling Get with a key that isn't changing? We are just trying to validate that including {0} doesn't cause any change in behaviour.

Edit:

I realised I forgot to mention that we are using PerBaseUrlFlurlClientFactory as our implementation of IFlurlClientFactory

1

There are 1 best solutions below

1
mason On

The default caching behavior for Flurl utilizes the scheme, host, and port of the URL. It does not use the path. Therefore, all of these calls using the HTTPS scheme, my.api.com host, and port 443 will use the same client.

This is mentioned in the docs:

With the clientless pattern, all calls to the same host (or more accurately, same combination of scheme/host/port) will reuse the same client.

You can override the caching behavior if you need to, but it's probably unnecessary for the scenario you have described.