ShadowApiNet 0.2.1

dotnet add package ShadowApiNet --version 0.2.1
                    
NuGet\Install-Package ShadowApiNet -Version 0.2.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ShadowApiNet" Version="0.2.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ShadowApiNet" Version="0.2.1" />
                    
Directory.Packages.props
<PackageReference Include="ShadowApiNet" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add ShadowApiNet --version 0.2.1
                    
#r "nuget: ShadowApiNet, 0.2.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package ShadowApiNet@0.2.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=ShadowApiNet&version=0.2.1
                    
Install as a Cake Addin
#tool nuget:?package=ShadowApiNet&version=0.2.1
                    
Install as a Cake Tool

ShadowApiNet

alternate text is missing from this package README image alternate text is missing from this package README image

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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.