Web Services¶
When connecting to external web services from within a Dataverse plugin, there are few common performance issues to be aware of. For instance, you must close connections after each use and set a reasonable timeout on the requests.
To help enforce these best practices and simplify calls to web services, you can use the IHttpService interface.
namespace Sample.Plugins
{
using Imprevis.Dataverse.Plugins;
using System.Collections.Generic;
public class TestPlugin : Plugin<TestPluginRunner> { }
public class TestPluginRunner : IPluginRunner
{
public TestPluginRunner(IHttpService httpService)
{
HttpService = httpService;
}
public IHttpService HttpService { get; }
public void Execute()
{
var posts = HttpService.Send<List<Post>>("GET", "https://jsonplaceholder.typicode.com/posts");
foreach (var post in posts)
{
// Do something!
}
}
}
}