microsoft/teams.net

Public

mirrored fromhttps://github.com/microsoft/teams.netAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
5c4075027232b28388ab1e973b9d2407df669d63

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

Libraries/Microsoft.Teams.Common/Http/HttpRequest.cs

71lines · modepreview

// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

namespace Microsoft.Teams.Common.Http;

public interface IHttpRequest : IHttpRequestOptions
{
    public HttpMethod Method { get; set; }
    public string Url { get; set; }
    public object? Body { get; set; }
}

public class HttpRequest : HttpRequestOptions, IHttpRequest
{
    public required HttpMethod Method { get; set; }
    public required string Url { get; set; }
    public object? Body { get; set; }

    public static HttpRequest Get(string url, IHttpRequestOptions? options = null)
    {
        return new HttpRequest()
        {
            Method = HttpMethod.Get,
            Url = url,
            Headers = options?.Headers ?? new Dictionary<string, IList<string>>(),
        };
    }

    public static HttpRequest Post(string url, object? body = default, IHttpRequestOptions? options = null)
    {
        return new HttpRequest()
        {
            Method = HttpMethod.Post,
            Url = url,
            Body = body,
            Headers = options?.Headers ?? new Dictionary<string, IList<string>>(),
        };
    }

    public static HttpRequest Patch(string url, object? body = default, IHttpRequestOptions? options = null)
    {
        return new HttpRequest()
        {
            Method = new HttpMethod("PATCH"),
            Url = url,
            Body = body,
            Headers = options?.Headers ?? new Dictionary<string, IList<string>>(),
        };
    }

    public static HttpRequest Put(string url, object? body = default, IHttpRequestOptions? options = null)
    {
        return new HttpRequest()
        {
            Method = HttpMethod.Put,
            Url = url,
            Body = body,
            Headers = options?.Headers ?? new Dictionary<string, IList<string>>(),
        };
    }

    public static HttpRequest Delete(string url, IHttpRequestOptions? options = null)
    {
        return new HttpRequest()
        {
            Method = HttpMethod.Delete,
            Url = url,
            Headers = options?.Headers ?? new Dictionary<string, IList<string>>(),
        };
    }
}