Consuming OData services

The Open Data protocol (OData) is a common way to expose a database as a REST API. Radzen Blazor Studio provides first class support for OData services. It scaffolds for you:

  • Service classes which make HTTP requests to the OData service and optionally authenticate.
  • Model classes for all entities.
  • Various pages that allow to to quickly make a full CRUD application from the OData service.

Connect to OData service

In the following tutorial we will show how to:

  1. Create an OData data source in Radzen Blazor Studio.
  2. Generate code for the entities.
  3. Display data.

The tutorial uses the public Northwind OData API available at https://services.odata.org/Experimental/Northwind/Northwind.svc.

Configure the OData API connection

  1. Create a new Blazor application in Radzen Blazor Studio or open an existing one.
  2. Click the button.
  3. Select OData as the data source type in the Create or update data source dialog. This opens the OData connection editor.
  4. Enter the Northwind OData API connection details
    • Set Name to Northwind. The name must be a valid C# identifier. It is used for namespaces and service class names.
    • Set URL to https://services.odata.org/Experimental/Northwind/Northwind.svc. Displays the OData editor with all service connection details filled
  5. Click Next. Radzen Blazor Studio will infer the metadata and display all entity sets and singletons.
  6. Check the items from the OData service that you want to generate code for (models and CRUD methods). Click Next. Displays inferred entities from the OData service
  7. Check Generate pages for CRUD operations (this is a premium feature). Pick the CRUD template.
  8. Select the entities you want CRUD pages generated for. In this case we will select the Category entity and uncheck Allow editing, Allow inserting and Allow deleting. Click Finish. Displays the CRUD page configuration

Radzen Blazor Studio will:

  1. Create a NorthwindService class which can fetch data from the Northwind OData service.
  2. Create model classes for all checked entities.
  3. Create a Categories.razor page which will list the categories from the Northwind OData service.

Shows how the final result looks in the browser

Use the MSGraph API

Here is how create a OData Data Source for the MSGraph API.

  1. Create a new OData data source.
  2. Set Name to MSGraph.
  3. Set URL to https://graph.microsoft.com/v1.0/.
  4. Set Authorization type to OAuth2.
  5. Set Client ID and Client Secret from your Azure AD app settings.
  6. Set Authorization URL to https://login.microsoftonline.com/<tenant-id>/oauth2/v2.0/authorize (replace tenant-id with your AzureAD tenant id).
  7. Set Access Token URL to https://login.microsoftonline.com/<tenant-id>/oauth2/v2.0/token (replace tenant-id with your AzureAD tenant id).
  8. Set Scope to openid.
  9. Click Next to infer the MSGraph API.
  10. Check the entities and or singletons you want to use.

IMPORTANT! The MSGraph API has a lot of surface and checking all entities and singletons would lead to scaffolding a few thousand files. Check only the entities that you plan to use.