Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
I need to load data from an external site. For various reason I can not load it using ajax. I therefore need to do it in C#.
I have followed this guide: https://our.umbraco.com/documentation/reference/routing/custom-controllers
And came up with the following code:
public class HomeController : RenderMvcController { private static readonly HttpClient client = new HttpClient(); public override ActionResult Index(ContentModel model) { var responseTask = client.GetStringAsync("https://www.alphavantage.co/query?function=GLOBAL_QUOTE&symbol=AAPL&apikey=XXXXX"); string response = responseTask.Result; var result = JsonConvert.DeserializeObject<Dictionary<string, Dictionary<string, string>>>(response); ViewBag.StockPrice = result["Global Quote"]["05. price"]; return base.Index(model); } }
Is this the preferred way to do it? Or is there a better way?
When doing it this way will the page be cached?
Hi Frederik,
The preferred way would be to add caching :) It will be probably quite slow to call external service each page load.
Alex
What is the preferred way to do caching? Let say I want new content every 20 min.
I have read https://our.umbraco.com/documentation/reference/cache/, but it is lacking information.
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.
Continue discussion
Loading data from external site
I need to load data from an external site. For various reason I can not load it using ajax. I therefore need to do it in C#.
I have followed this guide: https://our.umbraco.com/documentation/reference/routing/custom-controllers
And came up with the following code:
Is this the preferred way to do it? Or is there a better way?
When doing it this way will the page be cached?
Hi Frederik,
The preferred way would be to add caching :) It will be probably quite slow to call external service each page load.
Alex
What is the preferred way to do caching? Let say I want new content every 20 min.
I have read https://our.umbraco.com/documentation/reference/cache/, but it is lacking information.
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.