Skip to content

Twilio SendGrid's C# HTTP Client for calling APIs

License

Notifications You must be signed in to change notification settings

sendgrid/csharp-http-client

Folders and files

NameName
Last commit message
Last commit date

Latest commit

37ad381 · Mar 9, 2022
Feb 28, 2022
Mar 9, 2022
Aug 15, 2019
Nov 22, 2021
Oct 4, 2018
Aug 18, 2020
Aug 15, 2019
Mar 9, 2022
Apr 9, 2020
Aug 24, 2020
Oct 14, 2020
Aug 3, 2020
Jan 4, 2022
Jan 29, 2020
Oct 15, 2020
Feb 3, 2022
Aug 15, 2019
Aug 7, 2020
Jan 28, 2020
Aug 7, 2020

Repository files navigation

SendGrid Logo

Test and Deploy NuGet MIT licensed Twitter Follow GitHub contributors

Quickly and easily access any RESTful or RESTful-like API.

If you are looking for the Twilio SendGrid API client library, please see this repo.

Table of Contents

Announcements

The default branch name for this repository has been changed to main as of 07/27/2020.

All updates to this project are documented in our CHANGELOG.

Installation

Prerequisites

  • .NET Framework 4.5+

Install Package

To use CSharp.HTTP.Client in your C# project, you can either download the Twilio SendGrid C# .NET libraries directly from our Github repository or, if you have the NuGet package manager installed, you can grab them automatically.

PM> Install-Package SendGrid.CSharp.Http.Client

Once you have the library properly referenced in your project, you can include calls to them in your code. For a sample implementation, check the Example folder.

Add the following namespace to use the library:

using SendGrid.CSharp.HTTP.Client;

Quick Start

Here is a quick example:

GET /your/api/{param}/call

using SendGrid.CSharp.HTTP.Client;
globalRequestHeaders.Add("Authorization", "Bearer XXXXXXX");
dynamic client = new Client(host: baseUrl, requestHeaders: globalRequestHeaders);
var response = await client.your.api._(param).call.get()
Console.WriteLine(response.StatusCode);
Console.WriteLine(response.Body.ReadAsStringAsync().Result);
Console.WriteLine(response.Headers.ToString());

POST /your/api/{param}/call with headers, query parameters and a request body with versioning.

using SendGrid.CSharp.HTTP.Client;
using Newtonsoft.Json;
globalRequestHeaders.Add("Authorization", "Bearer XXXXXXX");
dynamic client = new Client(host: baseUrl, requestHeaders: globalRequestHeaders);
string queryParams = @"{'Hello': 0, 'World': 1}";
requestHeaders.Add("X-Test", "test");
string requestBody = @"{'some': 1, 'awesome': 2, 'data': 3}";
Object json = JsonConvert.DeserializeObject<Object>(requestBody);
var response = await client.your.api._(param).call.post(requestBody: json.ToString(),
                                                  queryParams: queryParams,
                                                  requestHeaders: requestHeaders)
Console.WriteLine(response.StatusCode);
Console.WriteLine(response.Body.ReadAsStringAsync().Result);
Console.WriteLine(response.Headers.ToString());

Use Cases

You can find a selection of use cases for this library in our Use Cases directory.

How to Contribute

We encourage contribution to our projects, please see our CONTRIBUTING guide for details.

Quick links:

Thanks

We were inspired by the work done on birdy and universalclient.

About

csharp-http-client is maintained and funded by Twilio SendGrid, Inc. The names and logos for csharp-http-client are trademarks of Twilio SendGrid, Inc.

If you need help installing or using the library, please check the Twilio SendGrid Support Help Center.

If you've instead found a bug in the library or would like new features added, go ahead and open issues or pull requests against this repo!

License

The MIT License (MIT)