msgraph-sdk-dotnet icon indicating copy to clipboard operation
msgraph-sdk-dotnet copied to clipboard

Support creating and sending arbitrary requests

Open MIchaelMainer opened this issue 5 years ago • 1 comments

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

MIchaelMainer avatar Apr 09 '19 08:04 MIchaelMainer

@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.

darrelmiller avatar Jun 26 '19 22:06 darrelmiller

this is available with httpclientfactory.

ddyett avatar Jan 26 '23 17:01 ddyett