microsoft/teams.net

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
copilot/sub-pr-277

Branches

Tags

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

Clone

HTTPS

Download ZIP

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

71lines · modecode

1// Copyright (c) Microsoft Corporation. All rights reserved.
2// Licensed under the MIT License.
3
4namespace Microsoft.Teams.Common.Http;
5
6public interface IHttpRequest : IHttpRequestOptions
7{
8 public HttpMethod Method { get; set; }
9 public string Url { get; set; }
10 public object? Body { get; set; }
11}
12
13public class HttpRequest : HttpRequestOptions, IHttpRequest
14{
15 public required HttpMethod Method { get; set; }
16 public required string Url { get; set; }
17 public object? Body { get; set; }
18
19 public static HttpRequest Get(string url, IHttpRequestOptions? options = null)
20 {
21 return new HttpRequest()
22 {
23 Method = HttpMethod.Get,
24 Url = url,
25 Headers = options?.Headers ?? new Dictionary<string, IList<string>>(),
26 };
27 }
28
29 public static HttpRequest Post(string url, object? body = default, IHttpRequestOptions? options = null)
30 {
31 return new HttpRequest()
32 {
33 Method = HttpMethod.Post,
34 Url = url,
35 Body = body,
36 Headers = options?.Headers ?? new Dictionary<string, IList<string>>(),
37 };
38 }
39
40 public static HttpRequest Patch(string url, object? body = default, IHttpRequestOptions? options = null)
41 {
42 return new HttpRequest()
43 {
44 Method = new HttpMethod("PATCH"),
45 Url = url,
46 Body = body,
47 Headers = options?.Headers ?? new Dictionary<string, IList<string>>(),
48 };
49 }
50
51 public static HttpRequest Put(string url, object? body = default, IHttpRequestOptions? options = null)
52 {
53 return new HttpRequest()
54 {
55 Method = HttpMethod.Put,
56 Url = url,
57 Body = body,
58 Headers = options?.Headers ?? new Dictionary<string, IList<string>>(),
59 };
60 }
61
62 public static HttpRequest Delete(string url, IHttpRequestOptions? options = null)
63 {
64 return new HttpRequest()
65 {
66 Method = HttpMethod.Delete,
67 Url = url,
68 Headers = options?.Headers ?? new Dictionary<string, IList<string>>(),
69 };
70 }
71}