LiteApi is .net core middleware inspired by MVC-style Controller/Action principles. It's still in beta and currently initial tests are showing that it can handle about 50%-90% more requests per second than MVC6 (asp.net core). Check getting started and performance comparison.
LiteApi is still in prerelease phase, to install it use nuget, or add it to project.json file manually:
Install-Package LiteApi -Pre
Super simple example of a controller:
public class TestController : LiteController
{
// will respond to /api/test/add?a=3&b=8
public int Add(int a, int b)
{
return a + b;
}
}
Restful controller:
[Restful]
public class PersonsController: LiteController
{
private readonly IPersonDataAccess _dataAccess;
public PersonsController(IPersonDataAccess dataAccess)
{
_dataAccess = dataAccess;
}
// method names are not affecting action routes
[HttpGet] // will respond to /api/persons?id={someGuid}
public PersonModel ById(Guid id) => _dataAccess.Get(id);
[HttpGet, ActionRoute("/{id}")] // will respond to /api/persons/{someGuid}
public PersonModel ByIdFromRoute([FromRoute]Guid id) => _dataAccess.Get(id);
[HttpGet] // will respond to /api/persons
public IEnumerable<PersonModel> All() => _dataAccess.GetAll();
[HttpPost] // will respond to /api/persons
public PersonModel Save(PersonModel model) => _dataAccess.Save(model);
[HttpPost, ActionRoute("/{id}")] // will respond to /api/persons/{someGuid}
public PersonModel Update(Guid id, PersonModel model) => _dataAccess.Update(id, model);
}
More complex examples:
[ControllerRoute("/api/v2/ops")]
public class OperationsController : LiteController
{
// will respond to /api/v2/ops/3/plus/8
[ActionRoute("/{a}/plus/{b}")]
[HttpGet] // [HttpGet] is optional, by default it's GET, otherwise you can use [HttpPost], [HttpPut] or [HttpDelete]
public int Add(int a, int b) => a + b;
// will respond to /api/v2/ops/sum?ints=3&ints=6&ints=4
public int Sum(IEnumerable<int> ints) => ints.Sum();
// will respond to /api/v2/ops/join?a.1=one&a.3=three&b.2=two
public IDictionary<int, string> Join(IDictionary<int, string> a, Dictionary<int, string> b)
{
Dictionary<int, string> c = new Dictionary<int, string>();
foreach (var keyValue in a)
{
c[keyValue.Key] = keyValue.Value;
}
foreach (var keyValue in b)
{
c[keyValue.Key] = keyValue.Value;
}
return c;
}
}
You can use attributes: HttpGetAttribute, HttpPostAttribute, HttpPutAttribute, HttpDeleteAttribute, by default action is GET if no attribute is set.
For more info check Docs.
For installation you can reference nuget package LiteApi
and use it in your startup class:
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using LiteApi;
namespace MyApp
{
public class Startup
{
// ... configure services ...
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.AddConsole();
app.UseStaticFiles(); // if you want static files (LiteApi does not support static files by itself)
app.UseLiteApi();
}
}
}
- Support for other document formats (XML out of the box, extensibility points for other types)
- Support for versioning using request header value, versioning using routes is supported with
ControllerRouteAttribute
- Enable multiple instances of the middleware to run in one app
- Performance testing, performance improvements with Roslyn code generators
- Support for generating OpenAPI documentation (Swagger)
- Stabilization, more testing
- Documentation and website liteapi.net
- Global filters
- Configuration to replace global API root route (replace "api" in URLs with custom string)
- Option to return raw JSON content from string and to set response code
- Extensibility point to enable replacing any internal service in the middleware
- Force HTTPS attribute and global config
- Support action parameters from request header (in 0.7.2)