Formula.SimpleAPI
1.0.0
See the version list below for details.
dotnet add package Formula.SimpleAPI --version 1.0.0
NuGet\Install-Package Formula.SimpleAPI -Version 1.0.0
<PackageReference Include="Formula.SimpleAPI" Version="1.0.0" />
paket add Formula.SimpleAPI --version 1.0.0
#r "nuget: Formula.SimpleAPI, 1.0.0"
// Install Formula.SimpleAPI as a Cake Addin #addin nuget:?package=Formula.SimpleAPI&version=1.0.0 // Install Formula.SimpleAPI as a Cake Tool #tool nuget:?package=Formula.SimpleAPI&version=1.0.0
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 | Versions 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. |
-
.NETCoreApp 3.1
- Formula.SimpleCore (>= 1.0.0)
- Formula.SimpleRepo (>= 1.0.0)
- Microsoft.AspNetCore.Mvc (>= 2.2.0)
- Newtonsoft.Json (>= 12.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.
Version | Downloads | Last updated |
---|---|---|
1.8.0 | 8,403 | 3/28/2024 |
1.6.0 | 33,360 | 8/22/2022 |
1.2.4 | 2,277 | 8/3/2022 |
1.2.3 | 823 | 7/28/2022 |
1.2.0 | 16,090 | 8/2/2021 |
1.1.6 | 2,040 | 8/2/2021 |
1.1.4 | 658 | 7/15/2021 |
1.1.3 | 449 | 7/14/2021 |
1.1.2 | 1,204 | 5/27/2021 |
1.1.1 | 445 | 5/27/2021 |
1.1.0 | 434 | 5/25/2021 |
1.0.3.4 | 2,169 | 10/6/2020 |
1.0.3 | 617 | 8/21/2020 |
1.0.2 | 589 | 5/24/2020 |
1.0.1 | 539 | 4/3/2020 |
1.0.0 | 650 | 2/22/2020 |