The API SDK makes it easy for client developers to generate data access code from the metadata exposed by the API documentation. The code generation techniques and the SDK are discussed in detail in the API Client Developers' Guide. The step-by-step instructions on client code generation are relatively brief, and are covered in that documentation.

However, if you have a local development instance of the Ed-Fi ODS / API, there is an even faster way to generate client code. It assumes you have a development instance of the Ed-Fi ODS / API running on your local machine.

This method of generating the API SDK does not currently generate endpoints for the "Other" section of the API (i.e. bulk operations and identity). If you need to generate these, then follow the instructions in Using Code Generation to Create an SDK.

 

The high-level steps are:

Each step is outlined in detail below.

Step 1. Restore NuGet Packages in the Visual Studio Solution

Ensure that all NuGet packages have been restored. The easiest way to do this is to build the solution, which is also a requirement for subsequent steps.

The first time that NuGet packages are restored, the script needed for Step 3 below won't be available. You'll first need to close and reopen the solution in order for the subsequent steps to work correctly.

Step 2. Launch the Swagger Metadata Project Without Debugging

First, ensure that you have followed the instructions for setting the startup projects in Visual Studio. To provide the code generation process with the necessary metadata, launch the project using Start Without Debugging (Ctrl+F5) in Visual Studio as shown below.

Wait until the SwaggerUI page loads successfully (thus ensuring that the Swagger metadata endpoints are functioning) before moving on to the next step.

If you do not use the Start Without Debugging option, you will not be able to perform Step 3 successfully.

Step 3. Generate SDK Client 

With the Swagger metadata endpoints active, open the "Package Manager Console" window. The window can be accessed via View > Other Windows... > Package Manager Console in Visual Studio. If this is the first time you've opened the console window during this Visual Studio session, PowerShell will perform some initialization of scripts. Once all the scripts have loaded, type the following into the console at the PM> prompt:

PM> Generate-Sdk.ps1

At this point, the API SDK client will be generated into the EdFi.Ods.Sdk project which is a "skeleton" project for the API SDK artifacts. Upon completion of the code generation process, modify the Program.cs file so that it contains your sandbox API key and secret, as follows:

// OAuth configuration
var oauthUrl = "http://localhost:54746/";
var clientKey = "0rCNunhFx1vO";  // TODO: Put your key here
var clientSecret = "z0luiQsTzyesxb8S6DdNyCDS"; // TODO: Put your secret here

Each time you generate the client, your customized key/secret will be overwritten in Program.cs.

The following image depicts the "Before" and "After" appearance of the project in the Solution Explorer:

Step 4. Run the Sample Program

To verify that the SDK client has been generated correctly, set the EdFi.Ods.Sdk project to be the Startup project. You can do this by right-clicking on the project node in the Solution Explorer and choosing the Set as StartUp Project menu item, as follows:

With the SDK project set as the Startup, and the other projects still running in the background after Step 2, run the project in Visual Studio. You should see the SDK console application display the following output:

At this point you can convert the EdFi.Ods.Sdk project to a Class Library in the project properties, and subsequently build it as a DLL assembly and reference it from a custom .NET application.