|
1 | 1 | [](https://travis-ci.org/sendgrid/csharp-http-client) |
2 | 2 |
|
3 | | -**Quickly and easily access any REST or REST-like API.** |
| 3 | +**This project allows you to quickly and easily access any REST or REST-like API.** |
| 4 | + |
| 5 | +# Announcements |
| 6 | + |
| 7 | +All updates to this project is documented in our [CHANGELOG](https://github.com/sendgrid/csharp-http-client/blob/master/CHANGELOG.md). |
| 8 | + |
| 9 | +# Installation |
| 10 | + |
| 11 | +To use CSharp.HTTP.Client in your C# project, you can either <a href="https://github.com/sendgrid/csharp-http-client.git">download the SendGrid C# .NET libraries directly from our Github repository</a> or, if you have the NuGet package manager installed, you can grab them automatically. |
| 12 | + |
| 13 | +``` |
| 14 | +PM> Install-Package SendGrid.CSharp.Http.Client |
| 15 | +``` |
| 16 | + |
| 17 | +Once you have the library properly referenced in your project, you can include calls to them in your code. |
| 18 | +For a sample implementation, check the [Example](https://github.com/sendgrid/csharp-http-client/tree/master/Example) folder. |
| 19 | + |
| 20 | +Add the following namespace to use the library: |
| 21 | +```csharp |
| 22 | +using SendGrid.CSharp.HTTP.Client; |
| 23 | +``` |
| 24 | + |
| 25 | +# Quick Start |
4 | 26 |
|
5 | 27 | Here is a quick example: |
6 | 28 |
|
@@ -33,162 +55,34 @@ Console.WriteLine(response.ResponseBody.ReadAsStringAsync().Result); |
33 | 55 | Console.WriteLine(response.ResponseHeaders.ToString()); |
34 | 56 | ``` |
35 | 57 |
|
36 | | -# Installation |
37 | | - |
38 | | -To use CSharp.HTTP.Client in your C# project, you can either <a href="https://github.com/sendgrid/csharp-http-client.git">download the SendGrid C# .NET libraries directly from our Github repository</a> or, if you have the NuGet package manager installed, you can grab them automatically. |
39 | | - |
40 | | -``` |
41 | | -PM> Install-Package SendGrid.CSharp.Http.Client |
42 | | -``` |
43 | | - |
44 | | -Once you have the library properly referenced in your project, you can include calls to them in your code. |
45 | | -For a sample implementation, check the [Example](https://github.com/sendgrid/csharp-http-client/tree/master/Example) folder. |
46 | | - |
47 | | -Add the following namespace to use the library: |
48 | | -```csharp |
49 | | -using SendGrid.CSharp.HTTP.Client; |
50 | | -``` |
51 | | - |
52 | | -## Usage ## |
53 | | - |
54 | | -Following is an example using SendGrid. You can get your free account [here](https://sendgrid.com/free?source=csharp-http-client). |
| 58 | +# Usage |
55 | 59 |
|
56 | | -First, update your Environment Variable with your [SENDGRID_APIKEY](https://app.sendgrid.com/settings/api_keys). |
| 60 | +- [Example Code](https://github.com/sendgrid/csharp-http-client/blob/master/Example/Example.cs) |
57 | 61 |
|
58 | | -Following is an abridged example, here is the [full working code](https://github.com/sendgrid/csharp-http-client/blob/master/Example/Example.cs). |
| 62 | +## Roadmap |
59 | 63 |
|
60 | | -```csharp |
61 | | -using System; |
62 | | -using System.Collections.Generic; |
63 | | -using SendGrid.CSharp.HTTP.Client; |
64 | | -using System.Web.Script.Serialization; |
65 | | - |
66 | | -class Example |
67 | | -{ |
68 | | - static void Main(string[] args) |
69 | | - { |
70 | | - String host = "https://api.sendgrid.com"; |
71 | | - Dictionary<String, String> requestHeaders = new Dictionary<String, String>(); |
72 | | - string apiKey = Environment.GetEnvironmentVariable("SENDGRID_APIKEY", EnvironmentVariableTarget.User); |
73 | | - requestHeaders.Add("Authorization", "Bearer " + apiKey); |
74 | | - requestHeaders.Add("Content-Type", "application/json"); |
75 | | - |
76 | | - String version = "v3"; |
77 | | - dynamic client = new Client(host, requestHeaders, version); |
78 | | - |
79 | | - // GET Collection |
80 | | - string queryParams = @"{ |
81 | | - 'limit': 100 |
82 | | - }"; |
83 | | - dynamic response = client.version("v3").api_keys.get(queryParams: queryParams); |
84 | | - var dssResponseBody = response.DeserializeResponseBody(response.ResponseBody); |
85 | | - foreach ( var value in dssResponseBody["result"]) |
86 | | - { |
87 | | - Console.WriteLine("name: {0}, api_key_id: {1}",value["name"], value["api_key_id"]); |
88 | | - } |
89 | | - |
90 | | - var dssResponseHeaders = response.DeserializeResponseHeaders(response.ResponseHeaders); |
91 | | - foreach (var pair in dssResponseHeaders) |
92 | | - { |
93 | | - Console.WriteLine("{0}: {1}", pair.Key, pair.Value); |
94 | | - } |
95 | | - |
96 | | - Console.WriteLine("\n\nPress any key to continue to POST."); |
97 | | - Console.ReadLine(); |
98 | | - |
99 | | - // POST |
100 | | - string requestBody = @"{ |
101 | | - 'name': 'My API Key 5', |
102 | | - 'scopes': [ |
103 | | - 'mail.send', |
104 | | - 'alerts.create', |
105 | | - 'alerts.read' |
106 | | - ] |
107 | | - }"; |
108 | | - response = client.api_keys.post(requestBody: requestBody); |
109 | | - Console.WriteLine(response.StatusCode); |
110 | | - Console.WriteLine(response.ResponseBody.ReadAsStringAsync().Result); |
111 | | - Console.WriteLine(response.ResponseHeaders.ToString()); |
112 | | - JavaScriptSerializer jss = new JavaScriptSerializer(); |
113 | | - var ds_response = jss.Deserialize<Dictionary<string, dynamic>>(response.ResponseBody.ReadAsStringAsync().Result); |
114 | | - string api_key_id = ds_response["api_key_id"]; |
115 | | - |
116 | | - Console.WriteLine("\n\nPress any key to continue to GET single."); |
117 | | - Console.ReadLine(); |
118 | | - |
119 | | - // GET Single |
120 | | - response = client.api_keys._(api_key_id).get(); |
121 | | - Console.WriteLine(response.StatusCode); |
122 | | - Console.WriteLine(response.ResponseBody.ReadAsStringAsync().Result); |
123 | | - Console.WriteLine(response.ResponseHeaders.ToString()); |
124 | | - |
125 | | - Console.WriteLine("\n\nPress any key to continue to PATCH."); |
126 | | - Console.ReadLine(); |
127 | | - |
128 | | - // PATCH |
129 | | - request_body = @"{ |
130 | | - 'name': 'A New Hope' |
131 | | - }"; |
132 | | - response = client.api_keys._(api_key_id).patch(requestBody: requestBody); |
133 | | - Console.WriteLine(response.StatusCode); |
134 | | - Console.WriteLine(response.ResponseBody.ReadAsStringAsync().Result); |
135 | | - Console.WriteLine(response.ResponseHeaders.ToString()); |
136 | | - |
137 | | - Console.WriteLine("\n\nPress any key to continue to PUT."); |
138 | | - Console.ReadLine(); |
139 | | - |
140 | | - // PUT |
141 | | - request_body = @"{ |
142 | | - 'name': 'A New Hope', |
143 | | - 'scopes': [ |
144 | | - 'user.profile.read', |
145 | | - 'user.profile.update' |
146 | | - ] |
147 | | - }"; |
148 | | - response = client.api_keys._(api_key_id).put(requestBody: requestBody); |
149 | | - Console.WriteLine(response.StatusCode); |
150 | | - Console.WriteLine(response.ResponseBody.ReadAsStringAsync().Result); |
151 | | - Console.WriteLine(response.ResponseHeaders.ToString()); |
152 | | - |
153 | | - Console.WriteLine("\n\nPress any key to continue to DELETE."); |
154 | | - Console.ReadLine(); |
155 | | - |
156 | | - // DELETE |
157 | | - response = client.api_keys._(api_key_id).delete(); |
158 | | - Console.WriteLine(response.StatusCode); |
159 | | - Console.WriteLine(response.ResponseHeaders.ToString()); |
160 | | - |
161 | | - Console.WriteLine("\n\nPress any key to exit."); |
162 | | - Console.ReadLine(); |
163 | | - } |
164 | | -} |
165 | | -``` |
166 | | - |
167 | | -# Announcements |
168 | | - |
169 | | -[2016.03.18] - We hit version 1! |
| 64 | +If you are intersted in the future direction of this project, please take a look at our [milestones](https://github.com/sendgrid/csharp-http-client/milestones). We would love to hear your feedback. |
170 | 65 |
|
171 | | -# Roadmap |
| 66 | +## How to Contribute |
172 | 67 |
|
173 | | -[Milestones](https://github.com/sendgrid/csharp-http-client/milestones) |
| 68 | +We encourage contribution to our projects, please see our [CONTRIBUTING](https://github.com/sendgrid/csharp-http-client/blob/master/CONTRIBUTING.md) guide for details. |
174 | 69 |
|
175 | | -# How to Contribute |
| 70 | +Quick links: |
176 | 71 |
|
177 | | -We encourage contribution to our libraries, please see our [CONTRIBUTING](https://github.com/sendgrid/csharp-http-client/blob/master/CONTRIBUTING.md) guide for details. |
178 | | - |
179 | | -* [Feature Request](https://github.com/sendgrid/csharp-http-client/blob/master/CONTRIBUTING.md#feature_request) |
180 | | -* [Bug Reports](https://github.com/sendgrid/csharp-http-client/blob/master/CONTRIBUTING.md#submit_a_bug_report) |
181 | | -* [Improvements to the Codebase](https://github.com/sendgrid/csharp-http-client/blob/master/CONTRIBUTING.md#improvements_to_the_codebase) |
| 72 | +- [Feature Request](https://github.com/sendgrid/csharp-http-client/blob/master/CONTRIBUTING.mdCONTRIBUTING.md#feature_request) |
| 73 | +- [Bug Reports](https://github.com/sendgrid/csharp-http-client/blob/master/CONTRIBUTING.md#submit_a_bug_report) |
| 74 | +- [Sign the CLA to Create a Pull Request](https://github.com/sendgrid/csharp-http-client/blob/master/CONTRIBUTING.md#cla) |
| 75 | +- [Improvements to the Codebase](https://github.com/sendgrid/csharp-http-client/blob/master/CONTRIBUTING.md#improvements_to_the_codebase) |
182 | 76 |
|
183 | 77 | # Thanks |
184 | 78 |
|
185 | 79 | We were inspired by the work done on [birdy](https://github.com/inueni/birdy) and [universalclient](https://github.com/dgreisen/universalclient). |
186 | 80 |
|
187 | 81 | # About |
188 | 82 |
|
189 | | -![SendGrid Logo] |
190 | | -(https://assets3.sendgrid.com/mkt/assets/logos_brands/small/sglogo_2015_blue-9c87423c2ff2ff393ebce1ab3bd018a4.png) |
191 | | - |
192 | 83 | csharp-http-client is guided and supported by the SendGrid [Developer Experience Team](mailto:dx@sendgrid.com). |
193 | 84 |
|
194 | | -csharp-http-client is maintained and funded by SendGrid, Inc. The names and logos for python-http-client are trademarks of SendGrid, Inc. |
| 85 | +csharp-http-client is maintained and funded by SendGrid, Inc. The names and logos for csharp-http-client are trademarks of SendGrid, Inc. |
| 86 | + |
| 87 | +![SendGrid Logo] |
| 88 | +(https://assets3.sendgrid.com/mkt/assets/logos_brands/small/sglogo_2015_blue-9c87423c2ff2ff393ebce1ab3bd018a4.png)ß |
0 commit comments