expressappframework-403561-backend-web-api-service-add-web-api-to-blazor-server.md
This topic describes how to add the Web API service to a Blazor Server project.
Install the following NuGet packages to the Blazor Server project (MySolution.Blazor.Server):
See the following topic for more information on how to install DevExpress NuGet packages: Choose Between Offline and Online DevExpress NuGet Feeds.
Use the code below to configure services for the Web API :
File: MySolution.Blazor.Server\Startup.cs
using DevExpress.ExpressApp.WebApi.Services;
using Microsoft.OpenApi.Models;
using Microsoft.AspNetCore.OData;
// ...
public void ConfigureServices(IServiceCollection services) {
// ...
services.AddXafWebApi(Configuration, options => {
// To make a Business Object available via Web API and
// to generate GET, POST, PUT, and DELETE HTTP methods for it,
// uncomment the following line.
// !!!
// options.BusinessObject<YourBusinessObject>();
// !!!
})
// In EF Core applications, do nothing.
// In XPO applications, uncomment the following line.
// !!!
// .AddXpoServices()
// !!!
;
services.AddControllers().AddOData((options, serviceProvider) => {
options
.AddRouteComponents("api/odata", new EdmModelBuilder(serviceProvider).GetEdmModel())
.EnableQueryFeatures(100);
});
services.AddSwaggerGen(c => {
c.EnableAnnotations();
c.SwaggerDoc("v1", new OpenApiInfo {
Title = "MySolution API",
Version = "v1",
Description = @"Use AddXafWebApi(Configuration, options) in the MySolution.Blazor.Server\Startup.cs file to make Business Objects available in the Web API."
});
});
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env) {
if(env.IsDevelopment()) {
// ...
app.UseSwagger();
app.UseSwaggerUI(c => {
c.SwaggerEndpoint("/swagger/v1/swagger.json", "MySolution WebApi v1");
});
}
// ...
}
The Web API supports all standard ASP.NET Core authentication techniques. See the following topic for more information: Authentication in Web API projects.
You can now create endpoints and test the Web API.
You can enable additional Web API Service modules in an existing application. For instructions, please refer to the topic that describes the required module:
A number of modules are available to you right away, without the need for manual registration:
Note
Additional modules listed above ship only as part of the DevExpress Universal Subscription.
See Also
Blazor Server Startup Structure
Backend Web API Service / REST API
Configure the OAuth2 Azure Authentication for the Web API
Authorize EF Core CRUD Operations and Download Reports in Blazor WebAssembly with OData Web API