ShadowApiNet 0.2.1
dotnet add package ShadowApiNet --version 0.2.1
NuGet\Install-Package ShadowApiNet -Version 0.2.1
<PackageReference Include="ShadowApiNet" Version="0.2.1" />
<PackageVersion Include="ShadowApiNet" Version="0.2.1" />
<PackageReference Include="ShadowApiNet" />
paket add ShadowApiNet --version 0.2.1
#r "nuget: ShadowApiNet, 0.2.1"
#:package ShadowApiNet@0.2.1
#addin nuget:?package=ShadowApiNet&version=0.2.1
#tool nuget:?package=ShadowApiNet&version=0.2.1
ShadowApiNet
Warning - the project is still in POC stage, so it might not feature a full functionality yet, functionality and usage might change as well.
ShadowApiNet is a tool that allows seamless generation of RESTful API in your ASP.NET Core app.
ShadowApiNet can generate RESTful API based on DbContext that you provide (hence you should manage DB connection yourself). And expose your SQL Database in a form of fully REST compliant API.
Installation
Using dotnet CLI:
dotnet add package ShadowApiNet
use --version to install spesific version.
Or using PackageManager Console:
PM> Install-Package ShadowApiNet
use -Version to install spesific version.
Usage
The following section demonstrates how you can plug in and use ShadowApiNet in your ASP.Net Core application.
First create your DbContext: (example from official EF Core docs)
public class BloggingContext : DbContext
{
public DbSet<Blog> Blogs { get; set; }
public DbSet<Post> Posts { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder options)
=> options.UseSqlite("Data Source=blogging.db");
}
public class Blog
{
[Key]
public int BlogId { get; set; }
public string Url { get; set; }
public List<Post> Posts { get; } = new List<Post>();
}
public class Post
{
[Key]
public int PostId { get; set; }
public string Title { get; set; }
public string Content { get; set; }
public int BlogId { get; set; }
public Blog Blog { get; set; }
}
And then in your Startup.cs add the following lines:
using ShadowApiNet.Extensions;
...
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext<BloggingContext>(ServiceLifetime.Singleton);
services.AddShadowApi(new BloggingContext());
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
app.UseShadowApi();
}
}
Now, when you start your application you'll be able to access generated API using /dataapi path.
For example:
curl http://localhost:5000/dataapi/blogs
will return all the Blogs that are in the database.
And:
curl http://localhost:5000/dataapi/blogs/1
will return Blog with Id 1 or 404 Not Found if Blog with such id does not exist.
In repository you will find a test project that shows how the library can be used.
Please be aware that generated API will expose your DB models to the API consumers. (In later versions it may support Automapper configuration)
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. 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. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- Microsoft.AspNetCore.Http.Abstractions (>= 2.2.0)
- Microsoft.AspNetCore.JsonPatch (>= 8.0.0)
- Microsoft.EntityFrameworkCore (>= 8.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.0)
- Newtonsoft.Json (>= 13.0.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.