Code Samples
This section has two types of content:
- Language quick-starts (C#, JavaScript, Python, Java) — self-contained copy-paste snippets covering authentication, mailboxes, interchanges, callbacks, and error handling. Start here if you want to make your first API call in your language of choice.
- Sample projects — full .NET 10 projects under
/samplesthat demonstrate complete integration patterns (console polling loop, web application, background service, Minimal API proxy, and SOAP).
Real, runnable sample projects for all supported languages will be published at github.com/LorenData/ecgrid-samples. That repository is being built out — check back for updates.
Common Conventions (.NET samples)
All .NET sample projects share the same foundational conventions:
- Framework: .NET 10 (
net10.0) - JSON:
System.Text.Json— Newtonsoft.Json is never used - HTTP:
IHttpClientFactoryfor all REST samples —new HttpClient()is never used directly in production-pattern code - Async:
async/awaitthroughout — no.Resultor.Wait() - Configuration: API keys loaded from
IConfiguration(user-secrets or environment variables) — never hardcoded in source
Sample Projects
| Project | Pattern | Demonstrates |
|---|---|---|
| REST Console | Console (.NET 10) | Basic REST: inbox check, download, confirm, upload |
| Web Application | ASP.NET Core MVC | MVC controller backed by ECGrid REST |
| Minimal API | ASP.NET Core | Lightweight proxy for common ECGrid endpoints |
| Background Service | Worker Service | Background polling loop with configurable interval |
| SOAP — HttpClient | Console (.NET 10) | Manual SOAP envelope construction via HttpClient |
| SOAP — SvcUtil | Console (.NET 10) | Type-safe SOAP via dotnet-svcutil proxy |
Prerequisites (.NET samples)
-
An active ECGrid API key (from your network administrator or portal)
-
SOAP samples only:
dotnet-svcutilglobal tooldotnet tool install -g dotnet-svcutil
Setting Your API Key (.NET samples)
# Run from within the sample project directory
dotnet user-secrets set "ECGrid:ApiKey" "your-key-here"
Or via environment variable:
# Windows (PowerShell)
$env:ECGRID__APIKEY = "your-key-here"
# Linux / macOS
export ECGRID__APIKEY=your-key-here
The double underscore (__) maps to ECGrid:ApiKey in appsettings.json.
REST vs SOAP
For new integrations use the REST samples. SOAP samples are for teams maintaining or migrating existing SOAP-based code.
See REST vs SOAP for a comparison.