Getting Started | Samples | Walkthrough Video
Get fully working CRUD API's in an instant!
Build & Nuget Status
Version | Build | Nuget |
---|---|---|
Main | 0.7.0 | |
VNext | 0.8.0 |
About
The API Generator is a tool that helps you create fully functioning CRUD microservices with ease. Whether you use C# classes or a JSON definition, the API Generator takes care of all the necessary components, such as routes, database handling, migrations, openapi spec, and OData. All you have to do is write your model, and you'll have a CRUD API complete with filtering, sorting, selectable fields, and all the other features offered by both OData and classic REST.
Creating a CRUD API has never been easier. With just a few lines of code, you can have a working API in no time. Here's a simple example:
/// <summary>
/// This is as simple as it gets, yes this is a working api ;)
/// </summary>
[Api("/simple")]
public class SimpleSample : IObjectBase<int>
{
public int Id { get; set; }
public string Name { get; set; }
public int Value { get; set; }
}
Or, if you prefer using JSON:
[Api("/people", ApiMethodsToGenerate.All )]
public class Person : Trackable,
IObjectBase<Guid>,
IBeforeUpdate<Person>, // Before Update Hook
IBeforeDelete<Person>, // BeforeDelete Hook
{
public string Name { get; set; }
public DateTime Date { get; set; }
public string Description { get; set; }
public int Age { get; set; }
public Guid Id { get; set; }
}
And this is also the FULL code for a working API using the JSON mode:
[
{
"name": "Car",
"route": "/cars",
"caching": true,
"cacheLiveTime": 1000,
"events": "POST,PUT,DELETE",
"idType": "int",
"Fields": [
{
"name": "Name",
"type": "String",
"maxLength": "200",
"nullable": false
}
]
}
]
Getting Started & Documentation
Read this for a more detailed guide -> https://www.tcdev.de/tcdev-api-generator-getting-started Or just follow these steps:
- Install the package
dotnet add package TCDev.ApiGenerator --prerelease
after the package is installed add this to your program.cs (or startup.cs)
// Add API Generator and load data
builder.Services.AddApiGeneratorServices()
//From Assembly with OData .AddAssemblyWithOData(Assembly.GetExecutingAssembly())
//or as JSON from Uri .AddAssemblyWithODataFromUri("https://raw.githubusercontent.com/DeeJayTC/net-dynamic-api/main/sample/SampleAppJson/ApiDefinition.json","")
//Or without OData .AddAssembly(Assembly.GetExecutingAssembly())
.AddDataContextSQL() // or Postgres or SQLite
.AddOData()
.AddSwagger(true);
Documentation
Samples
You can find samples for using the library in the samples repository, constantly updated to match latest version and features: