How to pass absolute url to Api.Get method in Zebble?

I tried to get products with the following code:

public static async Task<List<Product>> GetProducts()
{
    return await Get<List<Product>>("http://locahost:5919/api/products");
}

      

But it looks like the Get method only accepts relative urls and I need to pass the absolute url in the Api.Base.Url setting in the Config.xml file.

I also tried assigning an absolute URL via the BaseUrl property before the return statement, but that made no difference.

Another strange thing: if I insert a fake URL (for example http://www.yahoo.com ) as the Api.Base.Url value and run the project, the following error occurs. Error adding fake url for Api.Base.Url

So, if we need to make requests to different endpoints in different URLs in the same project, how can we achieve this?

+3


source to share


1 answer


Your guess is wrong. When you call:

Api.Get<TResponse>(someUrl);

      

Then:

  • If someUrl starts with http: // or https: // then it will be treated as an absolute URL.
  • Otherwise, it will be treated as relative, in which case, to find the absolute Url, Zebble will be prefixed with the Api.Base.Url configuration value .

Example:

If in your config.xml file you have:



<Api.Base.Url>https://my-server.com</Api.Base.Url>

      

Then the following line will send an HTTP request to " https://my-server.com/api/hello ":

Api.Get<TResponse>("api/hello");

      

But the Api.Base.Url value in your config.xml file will be ignored in the next call (as an absolute url):

Api.Get<TResponse>("https://some-absolute-url.com/...");

      

0


source







All Articles