Before you start
Some important information before getting started with the examples.
Using an API key
To make the examples as straightforward as possible, the ApodClient is initialized with a string literal as an API key.
var client = new ApodClient("YOUR_API_KEY_HERE");
You should not include the API key as a string literal in your source code. There are many better ways, a few examples listed below. Remember to add all files with sensitive data to your .gitignore
.
- Write an App.config file and use the ConfigurationManager.AppSettings property
- Read from a custom file containing the API key with the System.IO.File.ReadAllText method
- Set up an environment variable and use Environment.GetEnvironmentVariable
- Pass your API key as a command line argument and access it with the string[] args in your
Main
method
Disposing the client
There are many different ways of disposing objects in C#. To keep a consistent style in the examples, the alternative syntax for the using statement (demonstrated below) will be used, which was introduced with C# 8. If you do not have access to C# 8, refer to the chapter "Disposing the client" in the README for more examples on how to accomplish the same functionality.
using var client = new ApodClient();