Skip to content

About

A fully-featured REST API ASP.NET Core web application almost without writing any routine code

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Latest commit

 

History

12 Commits

Folders and files

Repository files navigation

Magicalizer Sample

Magicalizer logotype

Introduction

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.

Structure

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.

Quick Start

Open MyApp.slnx and run the app, or run it from the command line:

dotnet run --project MyApp

The 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/categories
GET: /v1/categories?name.contains=izza
GET: /v1/categories?products.any.photos.any.filename.endswith=.jpg&include=products.photos

The 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=ana

Or 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=ana

The same way, the products that have both photos:

GET: /v1/products?photos.any[0].filename.equals=Photo1.jpg&photos.any[1].filename.equals=Photo3.jpg
GET: /v1/categories/1
GET: /v1/categories/5?include=products.photos
GET: /v1/products
GET: /v1/products?id.in=1&id.in=2
GET: /v1/products?category.id.equals=5&sort=name&offset=0&limit=5
GET: /v1/products?category.id.equals=5&sort=-price,name&offset=0&limit=5
GET: /v1/products?category.name.equals=Pizza&name.contains=ana&include=category
POST: /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/1

The querying (filtering, sorting, paging, and inclusion) is described in the documentation.

Links

Magicalizer: https://magicalizer.net/

Documentation: https://docs.magicalizer.net/

Sources on GitHub: https://github.com/Magicalizer/Magicalizer

Author: https://sikorsky.pro/

License

Licensed under the Apache License 2.0, see also NOTICE.txt. The code follows the conventions of Magicalizer.

About

A fully-featured REST API ASP.NET Core web application almost without writing any routine code

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages