Formula.SimpleAPI 1.0.2

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

// Install Formula.SimpleAPI as a Cake Tool
#tool nuget:?package=Formula.SimpleAPI&version=1.0.2

Formula.SimpleAPI

Easy API's for .Net

Constrainable Resources

One of the main goals of this project was to provide an easy way to expose "resources" in a database through a RESTful API. This is accomplished by building upon the Formula.SimpleRepo project.

In addition to common CRUD operations against resources, you can easily perform queries through a JSON expressions.

Example.. If you have a resource that has a column called Color, from the REST query endpoint you can constrain results by the color red.

{color:'red'}

The items that you can constrain by aren't limited to columns, but can by dynamic attributes you can define on your repository. This allows you to define how business concepts translate to constrainable concepts on your models.

{color:'red',highAvailability:true}

In order to expose a resource, you must define a model and repository (see Formula.SimpleRepo ) Then create a Resource Controller

using System;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Formula.SimpleAPI;
using MyApi.Data.Repositories;
using MyApi.Data.Models;

namespace MyApi.Controllers
{
    [ApiController]
    [Route("[controller]")]
    public class TodoController : ResourceControllerBase<TodoController, Todo, TodoRepository>
    {
        public TodoController(ILogger<TodoController> logger, TodoRepository repository) : base(logger, repository)
        {
        }
    }
}

This controller alone provides the following fetch type routes

  • GetList - /todo = Returns all Todo records
  • Get - /todo/1 = Returns the Todo record with the id of 1
  • Query - /todo/query/{'type':'chores','deleted':false} = would return all todo items that are of type chore that have not been deleted

CORS Support via config file

A simple wrapper for CORS support can be supplied by a config file as a wrapper around the standard .net core utilities, allowing you to load your configuration from a config file.

To implement, modify your Startup.cs to include the following.

Add the following using;

using Formula.SimpleResourceServer;

Startup.cs - ConfigureServices

Some extension methods have been provided for you register your configuration. Within the ConfigureServices function of Startup.cs you can call services.AddSimpleCors providing it with an implementation of ICorsConfig.

This can be done by creating your own class that implements the ICorsConfig contract, manually, however a more common way to provide configuration is via a JSON configuration file within the project using the CorsConfigDefinition.

CoresConfigDefition with origins as null will allow CORS from any origin, otherwise, an array of origins may be proviced.

services.AddSimpleCors(CorsConfigDefinition.Get("corsConfig.json"));

You may also provide some defaults using a delegate.

services.AddSimpleCors(CorsConfigDefinition.Get("corsConfig.json", () =>
{
    var def = new CorsConfigDefinition();
    def.Origins = null; // All from any origin right now
    return def;
}));

(See ConfigLoader in Formula.SimpleCore for details on how this functionality may be leverage for other task)

Startup.cs - Configure

In the configure section of your app, you may call;

app.UseSimpleCors();

Packages / Projects Used

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  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. 
.NET Core netcoreapp3.1 is compatible. 
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
1.8.0 993 3/28/2024
1.6.0 32,739 8/22/2022
1.2.4 2,257 8/3/2022
1.2.3 789 7/28/2022
1.2.0 16,058 8/2/2021
1.1.6 2,009 8/2/2021
1.1.4 628 7/15/2021
1.1.3 417 7/14/2021
1.1.2 1,173 5/27/2021
1.1.1 427 5/27/2021
1.1.0 415 5/25/2021
1.0.3.4 2,150 10/6/2020
1.0.3 585 8/21/2020
1.0.2 553 5/24/2020
1.0.1 505 4/3/2020
1.0.0 619 2/22/2020