GenericApiNetCore.ClientLib 2023.11.17.424

There is a newer version of this package available.
See the version list below for details.
dotnet add package GenericApiNetCore.ClientLib --version 2023.11.17.424                
NuGet\Install-Package GenericApiNetCore.ClientLib -Version 2023.11.17.424                
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="GenericApiNetCore.ClientLib" Version="2023.11.17.424" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add GenericApiNetCore.ClientLib --version 2023.11.17.424                
#r "nuget: GenericApiNetCore.ClientLib, 2023.11.17.424"                
#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.
// Install GenericApiNetCore.ClientLib as a Cake Addin
#addin nuget:?package=GenericApiNetCore.ClientLib&version=2023.11.17.424

// Install GenericApiNetCore.ClientLib as a Cake Tool
#tool nuget:?package=GenericApiNetCore.ClientLib&version=2023.11.17.424                

GenericApiNetCore

GenericApiNetCore logo

Demo

GenericApiNetCore demo

Description

Create CURD api for aspnet core 6.0 quickly:

public interface IApiMethods<T>
{
    Task<IApiResult<List<T>>> CreateAsync(CreateRequest<T> entitysRequest);
    Task<IApiResult<List<T>>> UpdateAsync(UpdateRequest<T> entitysRequest);
    Task<IApiResult<List<T>>> PagingAsync(PagingRequest<T> pageRequest);
    Task<IApiResult<int>> DeleteAsync(DeleteRequest<T> idsRequest);
}

How to use

A. Server API

  1. Install Package GenericApiNetCore.Server

    PM> Install-Package GenericApiNetCore.Server
    
  2. Define you Entity model

    //[ApiInfoRequest("api/product")]
    public class Product
    {
        public Guid Id { get; set; } = Guid.NewGuid();
        public string? Name { get; set; } = DateTime.Now.ToString();
    }
    
  3. Implement method for IRepositoryMethods<Product>

    public abstract class RepositoryMethods<T> : IRepositoryMethods<T>
    {
        readonly List<T> entities = new List<T>();
    
        public async Task<List<T>> CreateAsync(List<T> entitysRequest)
        {
            entities.AddRange(entitysRequest);
            return entitysRequest;
        }
    
        public async Task<int> DeleteAsync(Guid[] idsRequest)
        {
            entities.RemoveAll(q => idsRequest.Contains(GetId(q)));
            return idsRequest.Length;
        }
    
        public abstract Guid GetId(T entity);
    
        public async Task<List<T>> PagingAsync(int pageRequest)
        {
            return entities.Skip((pageRequest - 1) * 5).Take(pageRequest * 5).ToList();
        }
    
        public async Task<List<T>> UpdateAsync(List<T> entitysRequest)
        {
            await DeleteAsync(entitysRequest.Select(q => GetId(q)).ToArray());
            await CreateAsync(entitysRequest);
            return entitysRequest;
        }
    }
    
    public class ProductRepositoryMethods : RepositoryMethods<Product>
    {
        public override Guid GetId(Product entity) => entity.Id;
    }
    
  4. Config Dependency injection Program.cs

    builder.Services.AddSingleton<IRepositoryMethods<Product>, ProductRepositoryMethods>();
    
  5. Create api

    using GenericApiNetCore.Samples.Entities;
    using GenericApiNetCore.ServerLib;
    using Microsoft.AspNetCore.Mvc;
    
    namespace GenericApiNetCore.WebApi.Controllers
    {
        [RouteGeneric(typeof(Product))]
        public class ProductController : GenericControllerBase<Product>
        {
            public ProductController(IRepositoryMethods<Product> repositoryMethods) : base(repositoryMethods)
            {
            }
    
        }
    }
    
    

B. Client call API

Just call api service

using GenericApiNetCore.ClientLib;
using GenericApiNetCore.Samples.Entities;

var baseAddress = new Uri("https://localhost:7013/");
using var client = new ClientApiMethod<Product>(baseAddress);
var data = await client.PagingAsync(new PagingRequest<Product>() { Payload = 1 });
return data;
Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  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. 
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.

Version Downloads Last updated
2023.11.17.1028 259 11/17/2023
2023.11.17.1024 124 11/17/2023
2023.11.17.1020 126 11/17/2023
2023.11.17.947 126 11/17/2023
2023.11.17.938 133 11/17/2023
2023.11.17.935 130 11/17/2023
2023.11.17.424 132 11/17/2023