3

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 seems that Get method accepts just relative URLs and I have to pass absolute URL in Api.Base.Url setting in Config.xml file.

I also tried assigning absolute URL via BaseUrl property before return statement, but it didn't make any difference.

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

So if we need to make requests to different End Points in different URLs in one project, how can we achieve that?

CoderMan
  • 31
  • 2

1 Answers1

0

Your assumption is incorrect. 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 prefix that with the config value of Api.Base.Url.

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 a HTTP request to "https://my-server.com/api/hello":

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

But the value of Api.Base.Url in your config.xml file will be ignored in the following call (as it's an absolute url):

Api.Get<TResponse>("https://some-absolute-url.com/...");
Paymon
  • 1,173
  • 1
  • 9
  • 26