SwiftApi 10.0.3
dotnet add package SwiftApi --version 10.0.3
NuGet\Install-Package SwiftApi -Version 10.0.3
<PackageReference Include="SwiftApi" Version="10.0.3" />
<PackageVersion Include="SwiftApi" Version="10.0.3" />
<PackageReference Include="SwiftApi" />
paket add SwiftApi --version 10.0.3
#r "nuget: SwiftApi, 10.0.3"
#:package SwiftApi@10.0.3
#addin nuget:?package=SwiftApi&version=10.0.3
#tool nuget:?package=SwiftApi&version=10.0.3
SwiftApi
SwiftApi is a powerful .NET class library that transforms your interfaces โ or even your model classes โ into fully functional API endpoints with zero controller boilerplate. Designed for speed, simplicity, and flexibility, SwiftApi enables you to build scalable APIs with minimal code and maximum control.
๐ Key Features
โ Zero Controllers
Automatically exposes your service interfaces or models as API endpoints โ no need to write a single controller.โ๏ธ Unlimited Endpoints
Add as many interfaces or model classes as you like โ SwiftApi handles the routing dynamically.๐ Built-in Security
Easily secure endpoints with support for various authentication schemes (Bearer, Basic, API Key, etc.).๐ Swagger Support
Built-in Swagger/OpenAPI integration for instant, interactive API documentation.๐งฉ Endpoint Management
Enable, disable, or configure individual endpoints via attributes or settings โ without touching controllers.๐พ Response Caching
Built-in support for caching GET responses for improved performance and scalability.๐งฑ Model-Based API Generation
Automatically generate basic CRUD endpoints directly from model classes.๐ฏ .NET 10 Compatible
Built on the latest .NET standards with full support for .NET 10 and future versions.
โ Supported Actions
SwiftApi currently supports the following HTTP actions via method attributes:
GetActionโ HTTP GETPostActionโ HTTP POSTPutActionโ HTTP PUTDeleteActionโ HTTP DELETE
๐ ๏ธ Getting Started
dotnet add package SwiftApi
๐ง Basic Interface Usage
- Define your interface:
[EndPoint("users")]
public interface IUserService
{
[GetAction]
Task<User?> GetUserByIdAsync([QueryParam] Guid id);
[GetAction("get-users")]
Task<List<User>> GetUsersAsync();
[PostAction("create-users")]
Task CreateUserAsync([BodyParam] User user);
[PutAction("update-users")]
Task UpdateUserAsync([RouteParam] Guid id, [BodyParam] User user);
[DeleteAction("delete-users")]
Task DeleteUserAsync([RouteParam] Guid id);
[PostAction(contentType: "multipart/form-data")]
void Upload([BodyParam] IFormFile file); //support upload with IFromFile type
[GetAction]
Stream Download(); // Support Download files with different type of return type (Stream, string path, bytes[])
}
- Define your schema:
[SchemaModel]
public class User
{
public Guid Id { get; set; }
public string Name { get; set; }
[Required]
public string Email { get; set; }
}
- Register SwiftApi in
Program.cs:
builder.Services.AddSwiftAPI();
app.MapSwiftAPI();
๐งฑ Model-Based Endpoint Generation (Interface Binding Required)
SwiftApi supports model-based endpoint generation by specifying the interface and its implementation directly on the model.
๐ Example with Generic Interface
[ModelEndPoint(typeof(IGenericService<User>), typeof(GenericService<User>))]
[SecureEndpoint]
public class User
{
public Guid Id { get; set; }
public string Name { get; set; }
[Required]
public string Email { get; set; }
}
๐ Example with Specific Interface
[ModelEndPoint(typeof(IPaymentService), typeof(PaymentService))]
public class Payment
{
public Guid Id { get; set; }
public string? Description { get; set; }
public decimal Amount { get; set; }
public DateTime PaymentDate { get; set; }
public string? Status { get; set; }
public string? PaymentMethod { get; set; }
public string? TransactionId { get; set; }
public string? Currency { get; set; }
}
Each model will generate full CRUD endpoints via the specified service interface and implementation.
๐ Securing Endpoints
Use attributes or configuration to secure endpoints per-method or globally.
๐ Securing Interface EndPoints
[EndPoint("users")]
[SecureEndpoint(role: "Admin,Manager")]
public interface IUserService
{
[GetAction("get-user-by-id")]
Task<User?> GetUserByIdAsync([QueryParam] Guid id);
[GetAction("get-users")]
[OpenAction] // Allows unauthenticated access
Task<List<User>> GetUsersAsync();
[PostAction("create-users")]
Task CreateUserAsync([BodyParam] User user);
[PutAction("update-users")]
Task UpdateUserAsync([RouteParam] Guid id, [BodyParam] User user);
[DeleteAction("delete-users")]
[SecureAction(policy: "delete")] //optional: specify the policy of the action
Task DeleteUserAsync([RouteParam] Guid id);
[PostAction(contentType: "multipart/form-data")]
void Upload([BodyParam] IFormFile file); //support upload with IFromFile type
[GetAction]
Stream Download(); // Support Download files with different type of return type (Stream, string path, bytes[])
}
๐ Securing Model EndPoints
[ModelEndPoint(typeof(IGenericService<User>),
typeof(GenericService<User>))]
[SecureEndpoint(role: "Admin,Manager")]
public class User
{
public Guid Id { get; set; }
public string Name { get; set; }
[Required]
public string Email { get; set; }
}
Update your SwiftApi registration:
builder.Services.AddSwiftAPI(o =>
{
//Basic
o.UseBasic(b =>
{
b.AuthCridentionals = new List<BasicAuthCridentional>{
new BasicAuthCridentional(username: "admin", password: "password")
};
});
//Bearer
o.UseBearer(bearer =>
{
bearer.JwtBearerOptions = jwt =>
{
jwt.Authority = "http://auth-server/auth/realms/master/protocol/openid-connect/token";
jwt.Audience = "app";
jwt.RequireHttpsMetadata = false;
jwt.TokenValidationParameters = new()
{
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes("Z9!sF2p@Q#7mV$L1C^T8WbXH6e4KJ0R*")),
ValidIssuer = "http://auth-server/auth/realms/master/protocol/openid-connect/token",
ValidAudience = "app",
ValidateIssuer = true,
ValidateAudience = true,
ValidateLifetime = true,
ValidateIssuerSigningKey = true
};
};
});
//ApiKey
o.UseApiKey(key =>
{
key.AuthCridentionals = new List<ApiKeyCridentional>
{
new ApiKeyCridentional(keyName: "Admin", keyValue: "123456")
};
});
//OAuth2
o.UseOAuth2(oAuth2 =>
{
oAuth2.JwtBearerOptions = jwt =>
{
jwt.Authority = "http://auth-server/auth/realms/master";
jwt.RequireHttpsMetadata = false;
jwt.TokenValidationParameters = new()
{
ValidIssuer = "http://auth-server/auth/realms/master",
ValidateIssuer = true,
ValidateAudience = false,
ValidateLifetime = true
};
};
oAuth2.AuthorizationUrl = "http://auth-server/auth/realms/master/protocol/openid-connect/auth";
oAuth2.TokenUrl = "http://auth-server/auth/realms/master/protocol/openid-connect/token";
});
//OpenIdConnect
o.UseOpenIdConnect(openIdConnect =>
{
openIdConnect.JwtBearerOptions = jwt =>
{
jwt.Authority = "http://auth-server/auth/realms/master";
jwt.RequireHttpsMetadata = false;
jwt.TokenValidationParameters = new()
{
ValidIssuer = "http://auth-server/auth/realms/master",
ValidateIssuer = true,
ValidateAudience = false,
ValidateLifetime = true
};
};
openIdConnect.OpenIdConnectConfigUrl = "http://auth-server/auth/realms/master/.well-known/openid-configuration";
});
});
Update your SwiftApi mapping:
app.MapSwiftAPI(enableAuth: true); //Add true to enable authorization
โก Response Caching
Enable response caching for GET methods using the enableCache and cacheDuration variables in the [GetAction()] attribute.
[GetAction(enableCache: true, cacheDuration: 5)] // default false, default duration 1 min
Task<List<User>> GetUsersAsync();
You can configure global cache behavior in Program.cs if needed.
๐งช Swagger Integration
Once your app is running, visit:
/swagger
To see your auto-generated, interactive documentation.
๐ License
This project is licensed under the MIT License.
๐โโ๏ธ Author
Nawaf AL-Maqbali
๐ง LinkedIn
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Microsoft.AspNetCore.Authentication.JwtBearer (>= 10.0.3)
- Microsoft.AspNetCore.OpenApi (>= 10.0.3)
- Swashbuckle.AspNetCore (>= 10.1.4)
- SwiftApi.Core (>= 10.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 | |
|---|---|---|---|
| 10.0.3 | 41 | 3/8/2026 | |
| 10.0.2 | 110 | 1/7/2026 | |
| 10.0.1 | 201 | 12/24/2025 | |
| 10.0.0 | 128 | 12/21/2025 | |
| 9.0.1 | 205 | 10/9/2025 | |
| 9.0.0 | 200 | 9/8/2025 | |
| 8.0.7 | 165 | 7/30/2025 | |
| 8.0.6 | 169 | 7/30/2025 | |
| 8.0.5 | 134 | 7/29/2025 | |
| 8.0.4 | 576 | 7/22/2025 | |
| 8.0.3 | 474 | 7/21/2025 | |
| 8.0.2 | 291 | 7/20/2025 | |
| 8.0.1 | 467 | 7/20/2025 | |
| 8.0.0 | 389 | 7/16/2025 | |
| 1.0.0 | 385 | 7/7/2025 |