msgraph-sdk-dotnet
msgraph-sdk-dotnet copied to clipboard
Support creating and sending arbitrary requests
Issue: The generated client library doesn't support creating arbitrary requests. We need a way to send arbitrary requests and get back deserialized objects.
The following snippet demonstrates a way to perform this. It requires the users to know which *request object to use. It does have the benefit of being consistent with the request builders and providing methods for each verb. Will this approach work if there isn't a *Request class for the return type? Investigate this for setting MailboxSettings. Is there a better approach here?
public static class GraphServiceClientExtensions
{
public static T Create<T>(this GraphServiceClient graphServiceClient, string url, IEnumerable<Option> options = null) where T: BaseRequest
{
var fullUrl = graphServiceClient.BaseUrl + url;
T request = (T)Activator.CreateInstance(typeof(T), new object[] { fullUrl, graphServiceClient, options });
return request;
}
}
var user = _graphServiceClient.Create<UserRequest>("/me").GetAsync().Result;
#263 AB#7321
@titusgicheru I wish you had shared this issue to help guide our conversation. This is a compromise between the Java way of doing it and the way that I was saying that someone would have to do it manually.
this is available with httpclientfactory.