-
Notifications
You must be signed in to change notification settings - Fork 0
GroupDocs.Editor RESTful for .Net
Creating GroupDocs.Editor RestFul Service with ASP.NET Core Web API
GroupDocs.Editor is a powerful document editing and manipulation API that developers can integrate into their applications. This guide will walk you through the process of setting up a GroupDocs.Editor RestFul Service using ASP.NET Core Web API.
Here's the step-by-step guide to creating a GroupDocs.Editor RestFul Service with ASP.NET Core Web API.
Begin by creating a new ASP.NET Core Web API project with .NET 6 framework. Open your terminal or command prompt and execute the following commands:
dotnet new webapi -n GroupDocsEditorService
cd GroupDocsEditorService
To integrate GroupDocs.Editor into your project, install the GroupDocs.Editor.UI.Api package. Run the following command in your terminal:
dotnet add package GroupDocs.Editor.UI.Api
Add controllers for handling document editing requests and Swagger for API documentation. Update your startup code as follows:
builder.Services.AddEditorControllers();
builder.Services.AddEditorSwagger();
builder.Services.AddEditor<AwsS3Storage>(builder.Configuration);
Utilize FeatureManagement to enable or disable parts of the Family formats supported by GroupDocs.Editor. Configure it as follows in your appsettings.json
file:
"FeatureManagement": {
"WordProcessing": true,
"LocalFile": true,
"Pdf": true,
"Presentation": true,
"Spreadsheet": true,
"Email": true
}
Configure the HTTP request pipeline to include Swagger UI in the development environment and map controllers. Update your startup code as follows:
if (app.Environment.IsDevelopment())
{
app.UseEditorSwaggerUI();
}
app.MapControllers();
Here's the code snippet for Program.cs
file incorporating the optional CORS policy for local development:
using GroupDocs.Editor.UI.Api.Extensions;
using GroupDocs.Editor.UI.Api.Services.Implementation;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
var builder = WebApplication.CreateBuilder(args);
// Add license for GroupDocs.Editor or remove for use Trial mode.
builder.Services.AddEditorLicense<Base64FileLicenseService>(builder.Configuration);
// Add services to the container.
builder.Services.AddEditorControllers();
builder.Services.AddEditorSwagger();
builder.Services.AddEditor<AwsS3Storage>(builder.Configuration);
// Optional: Add CORS policy for local development.
builder.Services.AddCors(p => p.AddPolicy("corsApp", policy =>
{
policy.WithOrigins("*").AllowAnyMethod().AllowAnyHeader().AllowAnyOrigin();
}));
var app = builder.Build();
// Configure the HTTP request pipeline.
app.UseHttpsRedirection();
if (app.Environment.IsDevelopment())
{
app.UseEditorSwaggerUI();
}
// Optional: Use CORS policy for local development.
app.UseCors(x => x
.AllowAnyOrigin()
.AllowAnyMethod()
.AllowAnyHeader());
app.MapControllers();
app.Run();
This version includes the optional CORS policy setup for local development, allowing requests from any origin during development.
In this guide, we've covered the process of creating a GroupDocs.Editor RestFul Service with ASP.NET Core Web API. By following these steps, you can integrate GroupDocs.Editor into your application, providing powerful document editing capabilities. Utilizing FeatureManagement allows you to customize the supported formats based on your application's requirements. Additionally, Swagger provides convenient API documentation for easier integration and testing.
Feel free to explore further functionalities and customization options provided by GroupDocs.Editor to optimize your document editing service.
- Creating GroupDocs.Editor RestFul Service with ASP.NET Core Web API
- Creating Document Editor Angular App
- Request example to GroupDocs.Editor RESTful API