RESTworld.Business
1.0.0
See the version list below for details.
dotnet add package RESTworld.Business --version 1.0.0
NuGet\Install-Package RESTworld.Business -Version 1.0.0
<PackageReference Include="RESTworld.Business" Version="1.0.0" />
paket add RESTworld.Business --version 1.0.0
#r "nuget: RESTworld.Business, 1.0.0"
// Install RESTworld.Business as a Cake Addin #addin nuget:?package=RESTworld.Business&version=1.0.0 // Install RESTworld.Business as a Cake Tool #tool nuget:?package=RESTworld.Business&version=1.0.0
RESTworld
RESTworld is a framework which utilizes other common frameworks and patterns alltogether to enable easy and fast creation of a truly RESTful API.
Used frameworks and patterns
- Entity Framework Core for data access
- ASP.Net Core for hosting
- HAL for providing hyperlinks between resources
- OData for query support on list endpoints
- AutoMapper for mapping between Entities and DTOs
Pipeline
The most basic pipeline has the following data flow for a request on a list endpoint:
- Request
- Controller selection through ASP.Net Core
- Query parsing through OData
- Controller method calls business service method
- Service gets the data through Entity Framework Core
- Entity Framework Core translates the query into SQL and gets the data from the database
- Business service translates Entities into DTOs through Automapper
- Controller wraps the result in a HAL response
- Result
Usage
Solution structure
If your API gets the name MyApi, structure your Solution with the following Projects:
- MyApi (ASP.Net Core Web API)
- References RESTworld.AspNetCore, MyApi.Business
- Contains your startup logic and your custom controllers
- MyApi.Business
- References RESTworld.Business, MyApi.Data
- Contains your AutoMapperConfiguration and your custom services
- MyApi.Data
- References RESTworld.EntityFrameworkCore, MyApi.Common
- Contains your Entity Framework Core Database Model including Entities and Migrations
- MyApi.Common
- References RESTworld.Common
- Contains your DTOs and Enums
Startup configuration
Add the following to your appsettings.json
"RESTworld": {
"MaxNumberForListEndpoint": <whatever is an appropriate number of resources for one page>
}
Change your Program.cs to the following
namespace MyApi
{
public class Program
{
public static void Main(string[] args)
{
RESTworld.AspNetCore.Program<Startup>.Main(args);
}
}
}
Change or add your Startup class
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using RESTworld.Business.Abstractions;
using MyApi.Common.Dtos;
using MyApi.Data;
using MyApi.Data.Models;
using MyApi.Business;
namespace MyApi
{
public class Startup : RESTworld.AspNetCore.StartupBase
{
public Startup(IConfiguration configuration)
: base(configuration)
{
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public override void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
base.Configure(app, env);
// Optionally migrate your database to the latest version during startup
MigrateDatabase<TDbContext>(app);
}
// This method gets called by the runtime. Use this method to add services to the container.
public override void ConfigureServices(IServiceCollection services)
{
// Database
services.AddDbContextFactoryWithDefaults<MyDatabase>(Configuration);
services.AddODataModelForDbContext<MyDatabase>();
// Default pipeline
services.AddRestPipeline<TContext, TEntity, TCreateDto, TGetListDto, TGetFullDto, TUpdateDto>();
// With custom service
services.AddRestPipelineWithCustomService<TContext, TEntity, TCreateDto, TGetListDto, TGetFullDto, TUpdateDto, TService>();
// With custom controller
services.AddRestPipelineWithCustomController<TContext, TEntity, TCreateDto, TGetListDto, TGetFullDto, TUpdateDto, TController>();
base.ConfigureServices(services);
}
protected override void ConfigureAutomapper(IMapperConfigurationExpression config)
=> new AutoMapperConfiguration().ConfigureAutomapper(config);
}
}
Add an AutoMapperConfiguration to your MyApi.Business project
using AutoMapper;
using MyApi.Common.Dtos;
using MyApi.Common.Enums;
using MyApi.Data.Models;
namespace MyApi.Business
{
public class AutoMapperConfiguration
{
public void ConfigureAutomapper(IMapperConfigurationExpression config)
{
config.CreateMap<TEntity, TDto>();
// Add more mappings
}
}
}
That's it. Now you can start your API and use a HAL browser like https://chatty42.herokuapp.com/hal-explorer/index.html#uri=https://localhost:5001 to browse your API.
If you are using a launchSettings.json
, I suggest to use this as your "launchUrl"
.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 is compatible. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net5.0
- AutoMapper (>= 10.1.1)
- EntityFrameworkCore.Parallel (>= 1.0.0)
- Microsoft.OData.Core (>= 7.8.3)
- RESTworld.EntityFrameworkCore (>= 1.0.0)
NuGet packages (2)
Showing the top 2 NuGet packages that depend on RESTworld.Business:
Package | Downloads |
---|---|
RESTworld.AspNetCore
Package Description |
|
RESTworld.Testing
Package Description |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
18.0.0 | 97 | 11/20/2024 |
17.1.2 | 242 | 11/7/2024 |
17.1.1 | 426 | 10/11/2024 |
17.1.0 | 202 | 9/27/2024 |
17.0.0 | 127 | 9/20/2024 |
16.0.1 | 430 | 7/10/2024 |
16.0.0 | 108 | 7/3/2024 |
15.0.0 | 163 | 6/4/2024 |
14.1.1 | 733 | 1/9/2024 |
14.1.0 | 175 | 12/22/2023 |
14.0.0 | 416 | 11/15/2023 |
13.1.0 | 346 | 10/23/2023 |
13.0.0 | 332 | 9/27/2023 |
12.2.2 | 205 | 9/11/2023 |
12.2.1 | 460 | 7/17/2023 |
12.2.0 | 304 | 7/3/2023 |
12.1.3 | 234 | 6/28/2023 |
12.1.2 | 442 | 6/14/2023 |
12.1.1 | 408 | 5/25/2023 |
12.1.0 | 433 | 4/30/2023 |
12.0.1 | 273 | 4/19/2023 |
12.0.0 | 334 | 3/12/2023 |
11.1.1 | 641 | 2/22/2023 |
11.1.0 | 354 | 2/9/2023 |
11.0.0 | 543 | 1/24/2023 |
10.1.0 | 368 | 1/24/2023 |
10.0.1 | 704 | 12/21/2022 |
10.0.0 | 595 | 11/9/2022 |
9.1.0 | 845 | 10/20/2022 |
9.0.0 | 757 | 10/20/2022 |
8.7.0 | 898 | 9/27/2022 |
8.6.0 | 1,129 | 6/28/2022 |
8.5.0 | 1,257 | 6/23/2022 |
8.4.2 | 969 | 6/8/2022 |
8.4.1 | 1,285 | 5/13/2022 |
8.4.0 | 1,167 | 4/1/2022 |
8.3.0 | 882 | 3/30/2022 |
8.2.2 | 1,649 | 3/13/2022 |
8.2.1 | 1,228 | 3/9/2022 |
8.2.0 | 937 | 3/8/2022 |
8.1.1 | 1,769 | 2/22/2022 |
8.1.0 | 942 | 2/22/2022 |
8.0.0 | 911 | 2/21/2022 |
7.0.0 | 738 | 1/14/2022 |
6.0.1 | 437 | 1/6/2022 |
6.0.0 | 862 | 12/3/2021 |
5.1.0 | 3,084 | 11/25/2021 |
5.0.2 | 715 | 11/4/2021 |
5.0.1 | 680 | 11/4/2021 |
5.0.0 | 1,229 | 10/6/2021 |
4.2.0 | 564 | 9/29/2021 |
4.1.0 | 534 | 9/27/2021 |
4.0.1 | 631 | 9/8/2021 |
4.0.0 | 505 | 9/7/2021 |
3.1.0 | 451 | 8/18/2021 |
3.0.0 | 494 | 7/7/2021 |
2.0.0 | 628 | 6/29/2021 |
1.2.0 | 525 | 5/11/2021 |
1.1.0 | 571 | 4/22/2021 |
1.0.0 | 872 | 3/31/2021 |