RESTworld.AspNetCore
1.0.2
See the version list below for details.
dotnet add package RESTworld.AspNetCore --version 1.0.2
NuGet\Install-Package RESTworld.AspNetCore -Version 1.0.2
<PackageReference Include="RESTworld.AspNetCore" Version="1.0.2" />
paket add RESTworld.AspNetCore --version 1.0.2
#r "nuget: RESTworld.AspNetCore, 1.0.2"
// Install RESTworld.AspNetCore as a Cake Addin #addin nuget:?package=RESTworld.AspNetCore&version=1.0.2 // Install RESTworld.AspNetCore as a Cake Tool #tool nuget:?package=RESTworld.AspNetCore&version=1.0.2
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>();
// Custom controllers will automatically be picked up by the pipeline so there is no need to register them.
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.Extensions.Microsoft.DependencyInjection (>= 8.1.1)
- HAL.AspNetCore.OData (>= 1.0.1)
- Microsoft.AspNetCore.OData.Versioning.ApiExplorer (>= 5.0.0)
- Microsoft.Extensions.Diagnostics.HealthChecks.EntityFrameworkCore (>= 5.0.4)
- RESTworld.Business (>= 1.0.0)
- Serilog.AspNetCore (>= 4.1.0)
- Serilog.Sinks.Async (>= 1.4.0)
- Swashbuckle.AspNetCore (>= 6.1.1)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on RESTworld.AspNetCore:
Package | Downloads |
---|---|
RESTworld.Client.AspNetCore
Package Description |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
26.3.3 | 74 | 11/7/2024 |
26.3.2 | 44 | 11/6/2024 |
26.3.1 | 71 | 10/30/2024 |
26.3.0 | 51 | 10/30/2024 |
26.2.0 | 245 | 10/11/2024 |
26.1.2 | 113 | 10/1/2024 |
26.1.1 | 64 | 10/1/2024 |
26.1.0 | 79 | 9/27/2024 |
26.0.0 | 72 | 9/20/2024 |
25.2.0 | 261 | 7/30/2024 |
25.1.2 | 100 | 7/18/2024 |
25.1.1 | 61 | 7/12/2024 |
25.1.0 | 223 | 7/10/2024 |
25.0.0 | 76 | 7/3/2024 |
24.1.0 | 110 | 6/10/2024 |
24.0.0 | 96 | 6/4/2024 |
23.0.0 | 64 | 6/4/2024 |
22.2.0 | 666 | 1/9/2024 |
22.0.0 | 149 | 12/22/2023 |
21.1.0 | 338 | 11/27/2023 |
21.0.1 | 128 | 11/27/2023 |
21.0.0 | 184 | 11/15/2023 |
20.1.0 | 310 | 10/23/2023 |
20.0.0 | 309 | 9/27/2023 |
19.2.2 | 203 | 9/11/2023 |
19.2.1 | 413 | 7/17/2023 |
19.2.0 | 246 | 7/3/2023 |
19.1.0 | 163 | 6/29/2023 |
19.0.0 | 189 | 6/28/2023 |
18.1.0 | 435 | 6/14/2023 |
18.0.2 | 377 | 5/25/2023 |
18.0.1 | 233 | 5/16/2023 |
18.0.0 | 273 | 5/10/2023 |
17.1.1 | 213 | 5/2/2023 |
17.1.0 | 227 | 4/30/2023 |
17.0.0 | 237 | 4/19/2023 |
16.0.0 | 276 | 3/12/2023 |
15.1.1 | 583 | 2/22/2023 |
15.1.0 | 304 | 2/9/2023 |
15.0.0 | 459 | 1/24/2023 |
14.1.0 | 357 | 1/24/2023 |
14.0.2 | 494 | 1/5/2023 |
14.0.1 | 308 | 1/5/2023 |
14.0.0 | 411 | 12/21/2022 |
13.0.0 | 537 | 11/9/2022 |
12.1.0 | 637 | 10/20/2022 |
12.0.0 | 526 | 10/20/2022 |
11.10.0 | 641 | 9/27/2022 |
11.9.0 | 825 | 6/28/2022 |
11.8.0 | 683 | 6/27/2022 |
11.7.0 | 636 | 6/23/2022 |
11.6.1 | 663 | 6/8/2022 |
11.6.0 | 633 | 6/7/2022 |
11.5.1 | 725 | 5/13/2022 |
11.5.0 | 982 | 4/1/2022 |
11.4.0 | 708 | 3/30/2022 |
11.3.1 | 831 | 3/16/2022 |
11.3.0 | 762 | 3/15/2022 |
11.2.4 | 774 | 3/13/2022 |
11.2.3 | 733 | 3/10/2022 |
11.2.2 | 749 | 3/9/2022 |
11.2.1 | 740 | 3/8/2022 |
11.1.3 | 914 | 3/7/2022 |
11.1.2 | 776 | 2/24/2022 |
11.1.1 | 745 | 2/22/2022 |
11.1.0 | 732 | 2/22/2022 |
11.0.0 | 755 | 2/21/2022 |
10.0.0 | 633 | 1/14/2022 |
9.0.4 | 400 | 1/6/2022 |
9.0.3 | 445 | 12/16/2021 |
9.0.2 | 425 | 12/9/2021 |
9.0.1 | 461 | 12/9/2021 |
9.0.0 | 329 | 12/3/2021 |
8.2.0 | 3,011 | 11/25/2021 |
8.1.1 | 573 | 11/4/2021 |
8.1.0 | 589 | 11/4/2021 |
8.0.0 | 642 | 10/28/2021 |
7.0.1 | 424 | 10/12/2021 |
7.0.0 | 447 | 10/6/2021 |
6.0.1 | 478 | 10/6/2021 |
6.0.0 | 432 | 10/6/2021 |
5.2.0 | 471 | 9/29/2021 |
5.1.0 | 420 | 9/27/2021 |
5.0.2 | 424 | 9/13/2021 |
5.0.1 | 405 | 9/8/2021 |
5.0.0 | 452 | 9/7/2021 |
4.1.0 | 393 | 8/18/2021 |
4.0.0 | 430 | 7/7/2021 |
3.0.0 | 445 | 7/5/2021 |
2.0.0 | 460 | 6/29/2021 |
1.2.0 | 422 | 5/11/2021 |
1.1.0 | 447 | 4/22/2021 |
1.0.3 | 415 | 4/1/2021 |
1.0.2 | 425 | 4/1/2021 |
1.0.1 | 383 | 4/1/2021 |
1.0.0 | 374 | 3/31/2021 |