This is a sample ASP.NET Core web application built with Magicalizer, a small and lightweight library that allows you to create a fully featured REST API with minimal routine code.
The app serves the menu of a restaurant: the categories, the products, and their photos. All it contains are the DTO, model, and entity classes, the filters, and the validators; the controllers and services are provided by Magicalizer.
| Folder | Contents |
|---|---|
MyApp/Dto |
The DTOs marked with [Magicalized] and their validators (the API layer) |
MyApp/Models |
The models and their validators (the domain layer) |
MyApp/Entities |
The entities and the database context (the data layer) |
MyApp/Filters |
The filters of the models |
CustomLanguageManager shows how to customize the messages of the validation errors, and
SqliteCompatibilityInterceptor makes SQLite sort the decimals correctly in any culture.
Open MyApp.slnx and run the app, or run it from the command line:
dotnet run --project MyAppThe app uses the SQLite database MyApp/db.sqlite with the test data (MyApp/db.sqlite.sql recreates it). The API is
described by OpenAPI at /openapi/v1.json, and Swagger UI at / lets you explore and try it in the browser.
Try the following requests:
GET: /v1/categoriesGET: /v1/categories?name.contains=izzaGET: /v1/categories?products.any.photos.any.filename.endswith=.jpg&include=products.photosThe conditions of the collection elements are passed in a single form, where one element must match all of them (no product of a category costs 200 or more and contains “ana” in its name at the same time, so nothing is found):
GET: /v1/categories?products.any.price.from=200&products.any.name.contains=anaOr in a list form with the indexes, where each filter is matched by any element (one product costs 200 or more, and another one contains “ana” in its name, so the Pizza category is found):
GET: /v1/categories?products.any[0].price.from=200&products.any[1].name.contains=anaThe same way, the products that have both photos:
GET: /v1/products?photos.any[0].filename.equals=Photo1.jpg&photos.any[1].filename.equals=Photo3.jpgGET: /v1/categories/1GET: /v1/categories/5?include=products.photosGET: /v1/productsGET: /v1/products?id.in=1&id.in=2GET: /v1/products?category.id.equals=5&sort=name&offset=0&limit=5GET: /v1/products?category.id.equals=5&sort=-price,name&offset=0&limit=5GET: /v1/products?category.name.equals=Pizza&name.contains=ana&include=categoryPOST: /v1/categories{"name": "Sushi"}PUT: /v1/categories{"id": 1, "name": "Not sushi"}PATCH: /v1/categories/1[{"op": "replace", "path": "/name", "value": "Sushi again o_O"}]DELETE: /v1/categories/1The querying (filtering, sorting, paging, and inclusion) is described in the documentation.
Magicalizer: https://magicalizer.net/
Documentation: https://docs.magicalizer.net/
Sources on GitHub: https://github.com/Magicalizer/Magicalizer
Author: https://sikorsky.pro/
Licensed under the Apache License 2.0, see also NOTICE.txt. The code follows the conventions of Magicalizer.